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(share/p2p): fix race in shrexeds test #2534

Merged
merged 1 commit into from
Aug 3, 2023
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
14 changes: 10 additions & 4 deletions share/p2p/shrexeds/exchange_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,27 @@ func TestExchange_RequestEDS(t *testing.T) {

// Testcase: EDS is unavailable initially, but is found after multiple requests
t.Run("EDS_AvailableAfterDelay", func(t *testing.T) {
storageDelay := time.Second
eds := edstest.RandEDS(t, 4)
dah, err := da.NewDataAvailabilityHeader(eds)
require.NoError(t, err)

lock := make(chan struct{})
go func() {
time.Sleep(storageDelay)
<-lock
err = store.Put(ctx, dah.Hash(), eds)
// require.NoError(t, err)
require.NoError(t, err)
lock <- struct{}{}
}()

requestedEDS, err := client.RequestEDS(ctx, dah.Hash(), server.host.ID())
assert.ErrorIs(t, err, p2p.ErrNotFound)
assert.Nil(t, requestedEDS)

time.Sleep(storageDelay * 2)
// unlock write
lock <- struct{}{}
// wait for write to finish
<-lock

requestedEDS, err = client.RequestEDS(ctx, dah.Hash(), server.host.ID())
assert.NoError(t, err)
assert.Equal(t, eds.Flattened(), requestedEDS.Flattened())
Expand Down
Loading