-
-
Notifications
You must be signed in to change notification settings - Fork 99
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for setup and teardown scripts #683
Comments
Help wanted: Is there anything I've missed here? Use cases and design suggestions would be welcome, especially if you've had practical experience with setup and teardown scripts in other contexts. I agree, this would be really cool! I don't think we can do a [[profile.default.setup]]
# optional, match by test filter and platform similar to overrides
filter = "..."
platform = "..."
command = "foo bar" # split using shell-words
timeout = "10s" # optional
[[profile.default.teardown]]
# similar Notes:
Some issues to work out:
|
(Note that I don't plan to work on this unless my employer decides to invest in this.) |
Some more thoughts based on discussion:
|
|
"Prior art" is originally a term from patent law. In this context it just means previous attempts to solve similar problems. |
Ah, I knew it under the other name (state of the art). Everyday learning something new ;) |
My employer has decided to invest in this, at least to get it to an experimental stage. Hoping to get an experimental version out in the next 2 weeks. |
Initial support for setup scripts is in #977. |
OK, just released experimental support for setup scripts with nextest 0.9.59. Documentation is at https://nexte.st/book/setup-scripts.html. @Dzordzu @alextes @ns-sjorgedeaguiar (since you liked the post) and others, please try it out and provide feedback in the tracking issue #978! |
I'm for running teardown scripts regardless if the setup script succeded or not and regardless if it was cancelled or not. The docs should be very explicit about teardown scripts being idempotent, meaning they should be prepared to be executed several times, and even if the setup script didn't run to completion, and the teardown script should not fail if the resource it needs to cleanup already was deleted (by the prev. run of the teardown script, for example).
For me, it's fine to leave the output uncaptured, and no prefixing is required. This would be relevant if there was an ability to run several setup scripts in parallel. I'm not sure
Right now, I personally don't have such a use case. It may make sense to wait until there is one?
I guess this should be configurable for teardown scripts at least. For example, if the teardown needs to shutdown a local docker container and it fails to do that then the testing should be considered "partially successful", a warning should be printed and the exit status should be zero, because the cost of leaking a local docker container isn't high, especially when the docker daemon is shutdown on an ephemeral CI runner after the the tests anyway. However, there may be cases like running So I suggest that by default, [script.errors]
# If exit code is not specified this means the following action is performed for all non-zero exit codes
action = "warn"
# Override handling of a specific exit code
[script.errors]
code = 255
action = "fail" Several more things to add. It usually makes sense to run the teardown script right before the setup script to ensure the environment is clean before the setup, otherwise the setup would try to create the resource that already exists. It should be easy to implement this for the users by moving their scripts to a file and invoking the teardown script at the beginning of the setup script. Therefore I'm not sure nextest needs a config-level capability to configure script dependencies such that the setup script would depend on the teardown script. . but it's something to keep in mind. It makes sense to have retry configs for the scripts just like for tests. For example, we do What about splitting |
It would be great to support |
With setup scripts, the main way to pass in context is via environment variables.
|
Hi, thanks for adding this experimental feature which I was able to use to solve the problem described at #1466. I have a script #!/bin/bash
# Exit with 1 if NEXTEST_ENV isn't defined.
if [ -z "$NEXTEST_ENV" ]; then
exit 1
fi
# Exit with 1 if $1 isnt set.
if [ -z "$1" ]; then
exit 1
fi
# Write out an environment variable to $NEXTEST_ENV.
echo "RUST_MIN_STACK=$1" >> "$NEXTEST_ENV" And then a bunch of limits added # Default
[script.add-stack-limit-80000]
command = "scripts/add-stack-limit.sh 80000"
[[profile.default.scripts]]
filter = "all()"
setup = "add-stack-limit-80000"
[script.add-stack-limit-700000]
command = "scripts/add-stack-limit.sh 700000"
[[profile.default.scripts]]
filter = "package(some-expensive-lib)"
setup = "add-stack-limit-700000" As I have about 12 |
Run code/script before any tests / after all the tests
Usecases
Configuration suggestion/examples
With shell code
With rust code
The text was updated successfully, but these errors were encountered: