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

Flaky test fix #28

Merged
merged 6 commits into from
Jan 10, 2020
Merged
Changes from 5 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
67 changes: 34 additions & 33 deletions retrievalmarket/network/libp2p_impl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func (tr *testReceiver) HandleQueryStream(s network.RetrievalQueryStream) {
defer s.Close()
if tr.queryStreamHandler != nil {
tr.queryStreamHandler(s)
return
}
}

Expand Down Expand Up @@ -132,7 +133,6 @@ func TestQueryStreamSendReceiveMultipleSuccessful(t *testing.T) {

func TestQueryStreamSendReceiveOutOfOrderFails(t *testing.T) {
// send query, read response in handler - fails
t.Skip("skipping due to flakiness")
ctxBg := context.Background()
td := shared_testutil.NewLibp2pTestData(ctxBg, t)
nw1 := network.NewFromLibp2pHost(td.Host1)
Expand All @@ -141,33 +141,33 @@ func TestQueryStreamSendReceiveOutOfOrderFails(t *testing.T) {
tr := &testReceiver{t: t}
require.NoError(t, nw1.SetDelegate(tr))

var receivedErr string
doneChan := make(chan bool)
tr2 := &testReceiver{t: t, queryStreamHandler: func(s network.RetrievalQueryStream) {
_, err := s.ReadQuery()
if err != nil {
receivedErr = "query"
}
doneChan <- true
}}
var errMsg string
done := make(chan bool)
tr2 := &testReceiver{t: t,
queryStreamHandler: func(s network.RetrievalQueryStream) {
_, err := s.ReadQuery()
if err != nil {
errMsg = "query"
}
done <- true
}}
require.NoError(t, nw2.SetDelegate(tr2))

qs1, err := nw1.NewQueryStream(td.Host2.ID())
require.NoError(t, err)

qr := shared_testutil.MakeTestQueryResponse()
require.NoError(t, qs1.WriteQueryResponse(qr))

ctx, cancel := context.WithTimeout(ctxBg, 10*time.Second)
defer cancel()

select {
case <-ctx.Done():
t.Error("never finished")
case <-doneChan:
}
go func() {
require.NoError(t, qs1.WriteQueryResponse(shared_testutil.MakeTestQueryResponse()))
ctx, cancel := context.WithTimeout(ctxBg, 10*time.Second)
defer cancel()
select {
case <-ctx.Done():
t.Error("never finished")
case <-done:
}
assert.Equal(t, "query", errMsg)
}()

assert.Equal(t, "query", receivedErr)
}

func TestDealStreamSendReceiveDealProposal(t *testing.T) {
Expand Down Expand Up @@ -308,7 +308,7 @@ func TestDealStreamSendReceiveMultipleSuccessful(t *testing.T) {
assert.Equal(t, dpy, receivedPayment)
}

func TestQueryStreamSendReceiveMultipleOutOfOrderFails(t *testing.T) {
func TestDealStreamSendReceiveOutOfOrderFails(t *testing.T) {
ctxBg := context.Background()
td := shared_testutil.NewLibp2pTestData(ctxBg, t)
nw1 := network.NewFromLibp2pHost(td.Host1)
Expand All @@ -327,21 +327,22 @@ func TestQueryStreamSendReceiveMultipleOutOfOrderFails(t *testing.T) {
done <- true
}}
require.NoError(t, nw2.SetDelegate(tr2))

qs1, err := nw1.NewDealStream(td.Host2.ID())
require.NoError(t, err)

require.NoError(t, qs1.WriteDealProposal(shared_testutil.MakeTestDealProposal()))
go func() {
require.NoError(t, qs1.WriteDealProposal(shared_testutil.MakeTestDealProposal()))

ctx, cancel := context.WithTimeout(ctxBg, 10*time.Second)
defer cancel()
select {
case <-ctx.Done():
t.Error("did not finish reading")
case <-done:
}
ctx, cancel := context.WithTimeout(ctxBg, 10*time.Second)
defer cancel()
select {
case <-ctx.Done():
t.Error("did not finish reading")
case <-done:
}
assert.Equal(t, "response", errMsg)
}()

assert.Equal(t, "response", errMsg)
}

// assertDealProposalReceived performs the verification that a deal proposal is received
Expand Down