Skip to content

Commit

Permalink
simplify wait
Browse files Browse the repository at this point in the history
  • Loading branch information
fredcarle committed Jun 26, 2024
1 parent 51048b2 commit 2fcac46
Showing 1 changed file with 14 additions and 22 deletions.
36 changes: 14 additions & 22 deletions tests/integration/p2p.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,17 +293,15 @@ func configureReplicator(
err = sourceNode.SetReplicator(s.ctx, client.Replicator{
Info: targetNode.PeerInfo(),
})
if err == nil {
<-sub.Message()
}

expectedErrorRaised := AssertError(s.t, s.testCase.Description, err, cfg.ExpectedError)
assertExpectedErrorRaised(s.t, s.testCase.Description, cfg.ExpectedError, expectedErrorRaised)
if err == nil {
setupReplicatorWaitSync(s, 0, cfg)
}
for msg := range sub.Message() {
if msg.Name == event.ReplicatorCompletedName {
break
}
}
}

func deleteReplicator(
Expand All @@ -318,12 +316,10 @@ func deleteReplicator(
err = sourceNode.DeleteReplicator(s.ctx, client.Replicator{
Info: targetNode.PeerInfo(),
})
require.NoError(s.t, err)
for msg := range sub.Message() {
if msg.Name == event.ReplicatorCompletedName {
break
}
if err == nil {
<-sub.Message()
}
require.NoError(s.t, err)
}

func setupReplicatorWaitSync(
Expand Down Expand Up @@ -408,15 +404,13 @@ func subscribeToCollection(
require.NoError(s.t, err)

err = n.AddP2PCollections(s.ctx, schemaRoots)
if err == nil {
<-sub.Message()
}

expectedErrorRaised := AssertError(s.t, s.testCase.Description, err, action.ExpectedError)
assertExpectedErrorRaised(s.t, s.testCase.Description, action.ExpectedError, expectedErrorRaised)

for msg := range sub.Message() {
if msg.Name == event.P2PTopicCompletedName {
break
}
}

// The `n.Peer.AddP2PCollections(colIDs)` call above is calling some asynchronous functions
// for the pubsub subscription and those functions can take a bit of time to complete,
// we need to make sure this has finished before progressing.
Expand Down Expand Up @@ -447,15 +441,13 @@ func unsubscribeToCollection(
require.NoError(s.t, err)

err = n.RemoveP2PCollections(s.ctx, schemaRoots)
if err == nil {
<-sub.Message()
}

expectedErrorRaised := AssertError(s.t, s.testCase.Description, err, action.ExpectedError)
assertExpectedErrorRaised(s.t, s.testCase.Description, action.ExpectedError, expectedErrorRaised)

for msg := range sub.Message() {
if msg.Name == event.P2PTopicCompletedName {
break
}
}

// The `n.Peer.RemoveP2PCollections(colIDs)` call above is calling some asynchronous functions
// for the pubsub subscription and those functions can take a bit of time to complete,
// we need to make sure this has finished before progressing.
Expand Down

0 comments on commit 2fcac46

Please sign in to comment.