-
Notifications
You must be signed in to change notification settings - Fork 81
fix(tests): prevent race condition in postgres driver tests #3673
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1422,6 +1422,21 @@ proc removeOldestPartition( | |
| proc containsAnyPartition*(self: PostgresDriver): bool = | ||
| return not self.partitionMngr.isEmpty() | ||
|
|
||
| proc waitForPartition*( | ||
| self: PostgresDriver, timeout = chronos.seconds(5) | ||
| ): Future[ArchiveDriverResult[void]] {.async.} = | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shall we mention that this is meant to avoid flaky testing only?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's just a generic timed wrapper for containsAnyPartition so I think we would have to put the same warning there as well. I'm not sure we should be afraid of people using timed-out queries to "a partition exists" outside of tests or as part of helping an actual test to test something useful. |
||
| let pollInterval = chronos.milliseconds(100) | ||
| var elapsed = chronos.milliseconds(0) | ||
|
|
||
| while elapsed < timeout: | ||
| if self.containsAnyPartition(): | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if we should confirm that there is a valid partition for "now".
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, if we step out of "there is a partition" as a basic check we may step into second-guessing what the partition manager is doing w.r.t. time calc. Maybe that's the actual solution to this. I should probably get more into what the partition manager actually does. Now I'm not sure I want to merge this fix as it is :-) I think this PR will linger here a bit since this testing race condition is so difficult to reproduce. It's the opposite of urgent. Certainly not triggering in the CI machines, which is slower than our own machines (where this is already very difficult to trigger). So this is worth waiting for doing actually right. |
||
| return ok() | ||
|
|
||
| await sleepAsync(pollInterval) | ||
| elapsed += pollInterval | ||
|
|
||
| return err("PostgresDriver.waitForPartition() timed out after " & $timeout) | ||
|
|
||
| method decreaseDatabaseSize*( | ||
| driver: PostgresDriver, targetSizeInBytes: int64, forceRemoval: bool = false | ||
| ): Future[ArchiveDriverResult[void]] {.async.} = | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.