From c90219633c40eaeb9ca69c7a8cea75123a13d596 Mon Sep 17 00:00:00 2001 From: Raito Bezarius Date: Fri, 27 Oct 2023 13:32:04 +0200 Subject: [PATCH] nixos/tests/nixos-test-driver: test timeout failures We test that the test framework timeouts are working as expected. --- nixos/tests/all-tests.nix | 8 ++++++++ nixos/tests/nixos-test-driver/timeout.nix | 15 +++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 nixos/tests/nixos-test-driver/timeout.nix diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index 1c8ee32428ea..2b50c09872ea 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -90,6 +90,14 @@ in { lib-extend = handleTestOn [ "x86_64-linux" "aarch64-linux" ] ./nixos-test-driver/lib-extend.nix {}; node-name = runTest ./nixos-test-driver/node-name.nix; busybox = runTest ./nixos-test-driver/busybox.nix; + driver-timeout = pkgs.runCommand "ensure-timeout-induced-failure" { + failed = pkgs.testers.testBuildFailure ((runTest ./nixos-test-driver/timeout.nix).config.rawTestDerivation); + } '' + grep -F "timeout reached; test terminating" $failed/testBuildFailure.log + # The program will always be terminated by SIGTERM (143) if it waits for the deadline thread. + [[ 143 = $(cat $failed/testBuildFailure.exit) ]] + touch $out + ''; }; # NixOS vm tests and non-vm unit tests diff --git a/nixos/tests/nixos-test-driver/timeout.nix b/nixos/tests/nixos-test-driver/timeout.nix new file mode 100644 index 000000000000..29bd85d2498e --- /dev/null +++ b/nixos/tests/nixos-test-driver/timeout.nix @@ -0,0 +1,15 @@ +{ + name = "Test that sleep of 6 seconds fails a timeout of 5 seconds"; + globalTimeout = 5; + + nodes = { + machine = ({ pkgs, ... }: { + }); + }; + + testScript = '' + start_all() + machine.wait_for_unit("multi-user.target") + machine.succeed("sleep 6") + ''; +}