Skip to content

Commit

Permalink
Make buffering test more robust, fix OSX on CI
Browse files Browse the repository at this point in the history
  • Loading branch information
tbidne committed Mar 14, 2024
1 parent 4a61460 commit d76b732
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
branches:
- main
- fix-tests

pull_request:
branches:
Expand Down
34 changes: 24 additions & 10 deletions test/functional/Functional/Buffering.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,29 +28,43 @@ logsNoBuffer =
-- literally i.e. {0..3}. The manual listing of indices appears to work,
-- however
args =
-- Having the indexes be 1.3, 2.6, ... rather than integers does not
-- change anything, but it makes the output slightly clearer.
withNoConfig
[ "--cmd-log",
"--cmd-log-strip-control=all",
"--cmd-name-trunc=15",
"for i in 0 1 2 3; do echo \"$i\"; sleep 1.5; done"
"sleep 0.5 ; for i in 0.5 1.5 2.5 3.5; do echo \"$i\"; sleep 1; done"
]

-- To test that the logs are correctly streamed, we check that actual
-- order of logs against the timing logs. This is a bit hacky, but the
-- sleep of 1.5 makes this fairly reliable.
-- sleep of 1.3 makes this more reliable.
--
-- Here is why we choose 1.3. We want to avoid a race between Timer logs
-- (every second) and Command logs, so we want these on different
-- intervals.
--
-- An offset of 1.5 would coincide at t=3, so this is not good.
-- The first collision with 1.3, on the other hand, is t=11, because the
-- LCM of 3 and 10 is 30. This is longer than the test runs, so this
-- should be okay.
--
-- An alternative would be to have the timer on the same interval (1 s) and
-- simply preface the loop with a sleep of 0.5 s.
cmdPrefix = "sleep 0.5 ; ..."
expecteds =
[ withCommandPrefix "for i in 0 1..." "Starting...",
withCommandPrefix "for i in 0 1..." "0",
[ withCommandPrefix cmdPrefix "Starting...",
withCommandPrefix cmdPrefix "0.5",
withTimerPrefix "1 second",
withCommandPrefix "for i in 0 1..." "1",
withCommandPrefix cmdPrefix "1.5",
withTimerPrefix "2 seconds",
withCommandPrefix "for i in 0 1..." "2",
withCommandPrefix cmdPrefix "2.5",
withTimerPrefix "3 seconds",
withCommandPrefix cmdPrefix "3.5",
withTimerPrefix "4 seconds",
withCommandPrefix "for i in 0 1..." "3",
withTimerPrefix "5 seconds",
withSuccessPrefix "for i in 0 1..." <> "6 seconds",
withFinishedPrefix "6 seconds"
withSuccessPrefix cmdPrefix <> "4 seconds",
withFinishedPrefix "4 seconds"
]

assertLogsEq :: List Text -> List Text -> IO ()
Expand Down

0 comments on commit d76b732

Please sign in to comment.