Replies: 1 comment 4 replies
-
Probably worth checking this example: https://github.com/dubzzz/fast-check/blob/main/examples/005-race/todolist/main.spec.tsx It uses a runner for model based testing tailored for scheduling. |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hey there, thanks for this fantastic library! I am trying to combine two ideas that are mentioned in the Tips section, namely model based testing and detecting race conditions with schedulers.
The setup I have is that I generate a sequence of commands for the system and run that against the system and model. The system can then (potentially) for every one of those commands fire off one promise. This promise I have configured as
s.schedule(Promise.resolve())
in my mock. I am very happy with this setup, and what I want is for fast-check to re-order the promise resolutions to detect race conditions - but I also want it to do this arbitrarily interleaved with the commands. I hope this makes sense!I tried making the commands async with
AsyncCommand
and.asyncModelRun
, however then the tests just never finish within Jest's timelimit. I don't need the commands themselves to be async (I don't think? since they only fire off promises, but never await them or return promises themselves), so I just reverted that and now use regular commands. This is fine by me.I also use
await s.waitAll()
to await all the promises. This has already found one race condition, so that's cool! But my question is this: is it valid to use regular un-async commands like this, together with scheduling promises? And will fast-check interleave these commands with the promises? Or will all commands run first, and then the promises will be resolved?Hope that makes sense, look forward to hearing from you!
Beta Was this translation helpful? Give feedback.
All reactions