Skip to content
This repository has been archived by the owner on Jun 19, 2023. It is now read-only.

Commit

Permalink
Merge pull request #45 from ipfs/fix/flaky-pubsub-test
Browse files Browse the repository at this point in the history
fix(test): fix a flaky pubsub test
  • Loading branch information
Stebalien committed Sep 27, 2019
2 parents 10d2073 + 00de46e commit 1c94e62
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion tests/pubsub.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,20 @@ func (tp *TestSuite) TestBasicPubSub(t *testing.T) {
t.Fatal(err)
}

done := make(chan struct{})
go func() {
defer close(done)

ticker := time.NewTicker(100 * time.Millisecond)
defer ticker.Stop()

for {
err := apis[1].PubSub().Publish(ctx, "testch", []byte("hello world"))
if err != nil {
switch err {
case nil:
case context.Canceled:
return
default:
t.Error(err)
cancel()
return
Expand All @@ -53,6 +60,13 @@ func (tp *TestSuite) TestBasicPubSub(t *testing.T) {
}
}()

// Wait for the sender to finish before we return.
// Otherwise, we can get random errors as publish fails.
defer func() {
cancel()
<-done
}()

m, err := sub.Next(ctx)
if err != nil {
t.Fatal(err)
Expand Down

0 comments on commit 1c94e62

Please sign in to comment.