Skip to content
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

Merged
merged 5 commits into from
Nov 26, 2024
Merged

Conversation

benbierens
Copy link
Contributor

Related to (but probably doesn't fix) #992

Copy link
Contributor

@emizzle emizzle left a 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?

@@ -190,7 +190,7 @@ asyncchecksuite "Sales":

proc allowRequestToStart {.async.} =
# wait until we're in initialproving state
await sleepAsync(10.millis)
check eventually clock.isWaiting
Copy link
Contributor

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")

Copy link
Contributor Author

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.

Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Contributor

@emizzle emizzle left a 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.} =
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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....

@benbierens benbierens added this pull request to the merge queue Nov 26, 2024
Merged via the queue into master with commit d47ce38 Nov 26, 2024
17 checks passed
@benbierens benbierens deleted the bug/fixes-racecondition-testsales branch November 26, 2024 12:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants