Using cargo-nextest to test synchronous blocking APIs #2276
-
Hello everybody! I want to test a synchronous API that may either block indefinitely or time out after a known deadline. My idea is to run it in a dedicated thread and have another thread wait until after the deadline. If my first thread testing the API is still running by then, the API has not timed out and is considered blocking. However, when the API is successfully detected as blocking, I need a way to kill the still-running thread. Rust provides no forceful ways to terminate another thread, and I cannot use any graceful ways given that my API is blocking indefinitely. I just discovered cargo-nextest and wonder if its process-per-test design can help me here. I can call Now I have two questions:
Is all of this even best practice? Or am I missing a better way to test blocking APIs? Thank you in advance, Colin Finck |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Thanks for the questions!
The process-per-test behavior is guaranteed to be the default behavior of nextest now and into the future. See https://nexte.st/docs/design/why-process-per-test for the rationale.
You can check for
Everything you said is quite reasonable. See the appendix in the first link for discussion about thread termination being hard. |
Beta Was this translation helpful? Give feedback.
Thanks for the questions!
The process-per-test behavior is guaranteed to be the default behavior of nextest now and into the future. See https://nexte.st/docs/design/why-process-per-test for the rationale.
You can check for
NEXTEST=1
andNEXTEST_EXECUTION_MODE=process-per-test
, as documented at https://nexte.st/docs/configuration/env-vars/#environment-variables-nextest-sets.