diff options
author | Jamie McClymont <jamie@kwiius.com> | 2022-03-03 19:01:44 +1300 |
---|---|---|
committer | Jamie McClymont <jamie@kwiius.com> | 2022-03-03 19:15:10 +1300 |
commit | 126ce87b0c7e526c8d1f2eccd868e89ef61deab3 (patch) | |
tree | c8f6b76b26b329ebe97fb58b23a80a951b17fa0d /nixos | |
parent | 2f7ef979c71bb6dd25744376e730a678379c7c62 (diff) | |
download | nixlib-126ce87b0c7e526c8d1f2eccd868e89ef61deab3.tar nixlib-126ce87b0c7e526c8d1f2eccd868e89ef61deab3.tar.gz nixlib-126ce87b0c7e526c8d1f2eccd868e89ef61deab3.tar.bz2 nixlib-126ce87b0c7e526c8d1f2eccd868e89ef61deab3.tar.lz nixlib-126ce87b0c7e526c8d1f2eccd868e89ef61deab3.tar.xz nixlib-126ce87b0c7e526c8d1f2eccd868e89ef61deab3.tar.zst nixlib-126ce87b0c7e526c8d1f2eccd868e89ef61deab3.zip |
nixos/tests: fix flaky cntr test
The cntr sometimes hangs until the 10-hour hydra limit. This behaviour appears to be an edge-case related to the type of TTY in which the cntr command runs during test execution. We can work around this by running the command as a background job. I additionally added a wait_for_open_port to fix nondeterministic test failures I observed after fixing the hanging issue.
Diffstat (limited to 'nixos')
-rw-r--r-- | nixos/tests/cntr.nix | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/nixos/tests/cntr.nix b/nixos/tests/cntr.nix index 668470756209..e4e13545b876 100644 --- a/nixos/tests/cntr.nix +++ b/nixos/tests/cntr.nix @@ -28,10 +28,16 @@ let testScript = '' start_all() ${backend}.wait_for_unit("${backend}-nginx.service") - result = ${backend}.wait_until_succeeds( - "cntr attach -t ${backend} nginx sh -- -c 'curl localhost | grep Hello'" + ${backend}.wait_for_open_port(8181) + # For some reason, the cntr command hangs when run without the &. + # As such, we have to do some messy things to ensure we check the exitcode and output in a race-condition-safe manner + ${backend}.execute( + "(cntr attach -t ${backend} nginx sh -- -c 'curl localhost | grep Hello' > /tmp/result; echo $? > /tmp/exitcode; touch /tmp/done) &" ) - assert "Hello" in result + + ${backend}.wait_for_file("/tmp/done") + assert "0" == ${backend}.succeed("cat /tmp/exitcode").strip(), "non-zero exit code" + assert "Hello" in ${backend}.succeed("cat /tmp/result"), "no greeting in output" ''; }; @@ -54,7 +60,13 @@ let testScript = '' machine.start() machine.wait_for_unit("container@test.service") - machine.succeed("cntr attach test sh -- -c 'ping -c5 172.16.0.1'") + # I haven't observed the same hanging behaviour in this version as in the OCI version which necessetates this messy invocation, but it's probably better to be safe than sorry and use it here as well + machine.execute( + "(cntr attach test sh -- -c 'ping -c5 172.16.0.1'; echo $? > /tmp/exitcode; touch /tmp/done) &" + ) + + machine.wait_for_file("/tmp/done") + assert "0" == machine.succeed("cat /tmp/exitcode").strip(), "non-zero exit code" ''; }; in { |