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

Fix race condition in testdiscoveryengine #1002

Merged
merged 2 commits into from
Nov 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions tests/codex/blockexchange/discovery/testdiscoveryengine.nim
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,11 @@ asyncchecksuite "Test Discovery Engine":
minPeersPerBlock = minPeers)
want = newAsyncEvent()

var pendingCids = newSeq[Cid]()
blockDiscovery.findBlockProvidersHandler =
proc(d: MockDiscovery, cid: Cid): Future[seq[SignedPeerRecord]] {.async, gcsafe.} =

check cid == blocks[0].cid
check cid in pendingCids
pendingCids.keepItIf(it != cid)
check peerStore.len < minPeers
var
peerCtx = BlockExcPeerCtx(id: PeerId.example)
Expand All @@ -126,8 +127,12 @@ asyncchecksuite "Test Discovery Engine":
want.fire()

await discoveryEngine.start()
var idx = 0
while peerStore.len < minPeers:
discoveryEngine.queueFindBlocksReq(@[blocks[0].cid])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ugh, but can't this happen in production settings too? Like, us requesting the same block more than once? Will the requests then maybe get cancelled sometimes?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you request discovery for a CID that's already in progress, the discovery engine will ignore it. This is the behavior we want. It's just that the test was running into this sometimes when it didn't want to.

let cid = blocks[idx].cid
inc idx
pendingCids.add(cid)
discoveryEngine.queueFindBlocksReq(@[cid])
await want.wait()
want.clear()

Expand Down