Uh oh!
There was an error while loading. Please reload this page.
fix(coverage): write hit records straight to disk instead of buffering them - #1103
Merged
Conversation
…g them The trap engine collected hits into a shell variable and wrote them out every 100 records. A variable dies with the subshell that filled it, so anything recorded inside a $( ) was lost unless that subshell happened to fill the buffer first. On Bash 5 a run of tests/unit/assert/basic_test.sh reported 196 of 236 real hits -- deterministically -- while Bash 3.2 lost none, so the same project measured differently depending on the Bash running it. The missing lines were ordinary code: bashunit::temp_dir and friends, called inside command substitutions. Appending each record is also faster than growing the string was: 8896ms to 5898ms on Bash 3.2, 4612ms to 3988ms on Bash 5, where hits go 196 to 236. A one-line append also interleaves better between parallel workers than a multi-kilobyte flush; sequential and parallel runs now report the same total. flush_buffer keeps its name and its callers -- it means "publish what I recorded", and now only drops the stale aggregation. The #724 guard against a spied printf moved with the write into record_line, and its test with it. Closes#1101
Three tests encoded the old behaviour as a documented limitation -- a hit recorded inside ( ), <( ) or a function called from $( ) never reached the data file, so they asserted the lower count. Those lines are recorded now: 1 to 2, 3 to 4, and 2 to 4. They are skipped on Bash 3.2, which is why the local runs stayed green and CI caught them on Linux.
They were skipped on macOS with a comment saying the DEBUG trap reaches subshells on Linux for every supported Bash. The Bash 3.0 job disproves that: the counts there are the pre-#1101 ones, because before Bash 4 the trap does not reach a subshell even under set -T, so nothing is recorded to keep. Skipping on BASH_VERSINFO < 4 states the real condition and covers both the macOS system Bash and the Bash 3.0 job.
… still does The engine section documented the buffer as a known difference -- the trap engine losing hits recorded inside a command substitution while xtrace kept them. Records are written as they happen now (#1101), so that difference is gone. What remains is the shell: before Bash 4 the DEBUG trap does not reach a subshell even under set -T, so the same project can report a slightly lower percentage on Bash 3.x. Worth saying out loud, since nothing in the output hints at it. The performance note claimed capture and reporting cost about the same. After this series the report phase is a few awk passes for the whole run and capture is the dominant half.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for freeto join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤔 Background
Related #1101
The trap engine collected hits into a shell variable and flushed every 100
records. A variable dies with the subshell that filled it, so anything recorded
inside a
$( )was lost unless that subshell happened to fill the bufferfirst.
On Bash 5 a run reported 196 of 236 real hits, deterministically, while
Bash 3.2 lost none — the same project measured differently depending on the
Bash running it. The missing lines were ordinary code called inside command
substitutions.
💡 Changes
( )and$( )and assert the record reached disk — all three fail against the buffered engineprintfmust not shadow the write) moved with the write intorecord_line, and its test with it