mirror of
https://github.com/logos-messaging/logos-messaging-nim.git
synced 2026-01-21 07:13:13 +00:00
fix: prevent race condition in postgres driver tests
* add PostgresDriver.waitForPartition * wait for a partition for 5s in archive driver tests setup
This commit is contained in:
parent
bc5059083e
commit
0305a3c0a0
@ -23,6 +23,8 @@ suite "Postgres driver":
|
||||
|
||||
driver = PostgresDriver(driverRes.get())
|
||||
|
||||
(await driver.waitForPartition()).expect("Test has no DB partition")
|
||||
|
||||
asyncTeardown:
|
||||
let resetRes = await driver.reset()
|
||||
if resetRes.isErr():
|
||||
|
||||
@ -38,6 +38,8 @@ suite "Postgres driver - queries":
|
||||
|
||||
driver = PostgresDriver(driverRes.get())
|
||||
|
||||
(await driver.waitForPartition()).expect("Test has no DB partition")
|
||||
|
||||
asyncTeardown:
|
||||
let resetRes = await driver.reset()
|
||||
|
||||
|
||||
@ -1422,6 +1422,22 @@ proc removeOldestPartition(
|
||||
proc containsAnyPartition*(self: PostgresDriver): bool =
|
||||
return not self.partitionMngr.isEmpty()
|
||||
|
||||
proc waitForPartition*(
|
||||
self: PostgresDriver, timeout = chronos.seconds(5)
|
||||
): Future[ArchiveDriverResult[void]] {.async.} =
|
||||
|
||||
let pollInterval = chronos.milliseconds(100)
|
||||
var elapsed = chronos.milliseconds(0)
|
||||
|
||||
while elapsed < timeout:
|
||||
if self.containsAnyPartition():
|
||||
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.} =
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user