Commit 72d64bd
logging: test that log lines accumulate instead of overwriting
148cdf7 replaced seekToEndOfFile() + write(data) with a POSIX append and
dropped the seek. FileHandle(forWritingTo:) opens at offset zero and write(2)
writes at the current offset, so every line overwrote from the start and the
file was left holding only the most recent one. 0b09c54 fixed it with an
lseek to SEEK_END under the append lock.
Nothing would have caught that. It compiles cleanly, and the round-trip check
used to justify the original change opened one descriptor, wrote once and read
back -- on an empty file offset zero already is the end, so a single write
passes with or without the seek. The bug only appears across repeated
open/write/close cycles, which is the actual usage pattern.
So test that pattern: write five lines through the logger and assert all five
survive. Verified it fails on the regression -- removing the lseek turns it from
passing in 0.022s into failing after the full poll deadline.
Testing it needs a writable directory, so the log location becomes an init
parameter with a convenience init() preserving FilePath.logsDirectory for
production. Applied to both platforms to keep the two files in step, though only
macOS has a test target to run it.
Verified locally on both: make macos-unit-tests reports TEST SUCCEEDED, and make
ios-compile-check builds Runner.app.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>1 parent 0b09c54 commit 72d64bd
3 files changed
Lines changed: 62 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
40 | | - | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
41 | 49 | | |
42 | | - | |
| 50 | + | |
43 | 51 | | |
44 | 52 | | |
45 | 53 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
10 | 52 | | |
11 | 53 | | |
12 | 54 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
44 | | - | |
45 | | - | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
46 | 54 | | |
47 | 55 | | |
48 | 56 | | |
| |||
0 commit comments