-
Notifications
You must be signed in to change notification settings - Fork 26
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
Fixes race in testsales #995
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for doing this PR, Ben, much appreciate! 🙏 However, this feels a bit flaky to me. Wdyt about the suggestion?
tests/codex/sales/testsales.nim
Outdated
@@ -190,7 +190,7 @@ asyncchecksuite "Sales": | |||
|
|||
proc allowRequestToStart {.async.} = | |||
# wait until we're in initialproving state | |||
await sleepAsync(10.millis) | |||
check eventually clock.isWaiting |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the underlying function changes (adding a waitUntil
in a certain sales state), then the test will fail and it may be a bit difficult to test. Instead, could we perhaps check the state? I think this should do it:
proc isInState(idx: int, state: string): bool =
proc description(state: State): string =
$state
sales.agents[idx].query(description) == state.some
check eventually isInState(0, "SaleInitialProving")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this, it seems a lot more reusable. I think isWaiting for a mockClock makes perfect sense. I'm giving this a try.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Be aware though that allowRequestToStart
may not actually have been checking that the state was in the initial proving state, so if you update it, some tests may break
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have applied your suggestion and I like it. The tests are all happy.
I know every keystroke I make reduces the likelihood that I can get this merged, BUT I did replace two more sleeps with check-eventually. Plz check if you agree with them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other than the async comment, it looks great! 🙏
@@ -188,9 +189,14 @@ asyncchecksuite "Sales": | |||
await repoTmp.destroyDb() | |||
await metaTmp.destroyDb() | |||
|
|||
proc isInState(idx: int, state: string): Future[bool] {.async.} = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this need to be async?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes: check-eventually is needed to give sales time to load the agent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, but shouldn't we just early return if sales.agent.len == 0
? I don't think there's a need for check eventually
in the isInState
proc, since its usage is used in a check eventually isInState...
.
Related to (but probably doesn't fix) #992