nixosTests.switchTest: fix race condition on /testpath

Currently the test-watch.service gets started in a loop as long as
/testpath exists, so `rm /testpath /testpath-modified` runs into a race
condition where if the service was just getting activated, it will
create /testpath-modified and make the test fail.

This is fixed by making the service RemainAfterExit so that it only
starts once, and stopping it manually after we remove /testpath.
This commit is contained in:
Naïm Favier 2022-02-25 18:03:55 +01:00 committed by Dominique Martinet
parent 4d12b79cd7
commit 8022c82a39

View File

@ -283,6 +283,7 @@ import ./make-test-python.nix ({ pkgs, ...} : {
systemd.services.test-watch = {
serviceConfig = {
Type = "oneshot";
RemainAfterExit = true;
ExecStart = "${pkgs.coreutils}/bin/touch /testpath-modified";
};
};
@ -723,6 +724,7 @@ import ./make-test-python.nix ({ pkgs, ...} : {
machine.succeed("touch /testpath")
machine.wait_until_succeeds("test -f /testpath-modified")
machine.succeed("rm /testpath /testpath-modified")
machine.systemctl("stop test-watch.service")
switch_to_specialisation("${machine}", "pathModified")
machine.succeed("touch /testpath")
machine.fail("test -f /testpath-modified")