diff options
author | Jacek Galowicz <jacek@galowicz.de> | 2022-01-08 18:28:25 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-08 18:28:25 +0100 |
commit | 048fd95f106ef4dca58ff01159207a027ab612d9 (patch) | |
tree | 3231875fa322010481f57a5d0b10102072709903 /nixos/doc/manual/development | |
parent | 41216b003f541efc899956a97106937e02f4aad2 (diff) | |
parent | 793a2f50f13f0c630cffbbb214f4128254945701 (diff) | |
download | nixpkgs-048fd95f106ef4dca58ff01159207a027ab612d9.tar nixpkgs-048fd95f106ef4dca58ff01159207a027ab612d9.tar.gz nixpkgs-048fd95f106ef4dca58ff01159207a027ab612d9.tar.bz2 nixpkgs-048fd95f106ef4dca58ff01159207a027ab612d9.tar.lz nixpkgs-048fd95f106ef4dca58ff01159207a027ab612d9.tar.xz nixpkgs-048fd95f106ef4dca58ff01159207a027ab612d9.tar.zst nixpkgs-048fd95f106ef4dca58ff01159207a027ab612d9.zip |
Merge pull request #146905 from Synthetica9/failure_mode
nixos/test-driver: add polling_condition
Diffstat (limited to 'nixos/doc/manual/development')
-rw-r--r-- | nixos/doc/manual/development/writing-nixos-tests.section.md | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/nixos/doc/manual/development/writing-nixos-tests.section.md b/nixos/doc/manual/development/writing-nixos-tests.section.md index d9749d37da7..7de57d0d2a3 100644 --- a/nixos/doc/manual/development/writing-nixos-tests.section.md +++ b/nixos/doc/manual/development/writing-nixos-tests.section.md @@ -88,6 +88,8 @@ starting them in parallel: start_all() ``` +## Machine objects {#ssec-machine-objects} + The following methods are available on machine objects: `start` @@ -313,3 +315,52 @@ repository): # fmt: on ''; ``` + +## Failing tests early {#ssec-failing-tests-early} + +To fail tests early when certain invariables are no longer met (instead of waiting for the build to time out), the decorator `polling_condition` is provided. For example, if we are testing a program `foo` that should not quit after being started, we might write the following: + +```py +@polling_condition +def foo_running(): + machine.succeed("pgrep -x foo") + + +machine.succeed("foo --start") +machine.wait_until_succeeds("pgrep -x foo") + +with foo_running: + ... # Put `foo` through its paces +``` + + +`polling_condition` takes the following (optional) arguments: + +`seconds_interval` + +: + specifies how often the condition should be polled: + + ```py + @polling_condition(seconds_interval=10) + def foo_running(): + machine.succeed("pgrep -x foo") + ``` + +`description` + +: + is used in the log when the condition is checked. If this is not provided, the description is pulled from the docstring of the function. These two are therefore equivalent: + + ```py + @polling_condition + def foo_running(): + "check that foo is running" + machine.succeed("pgrep -x foo") + ``` + + ```py + @polling_condition(description="check that foo is running") + def foo_running(): + machine.succeed("pgrep -x foo") + ``` |