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

Commit 1c94e62

Browse files
authored
Merge pull request #45 from ipfs/fix/flaky-pubsub-test
fix(test): fix a flaky pubsub test
2 parents 10d2073 + 00de46e commit 1c94e62

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

tests/pubsub.go

+15-1
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,20 @@ func (tp *TestSuite) TestBasicPubSub(t *testing.T) {
3434
t.Fatal(err)
3535
}
3636

37+
done := make(chan struct{})
3738
go func() {
39+
defer close(done)
40+
3841
ticker := time.NewTicker(100 * time.Millisecond)
3942
defer ticker.Stop()
4043

4144
for {
4245
err := apis[1].PubSub().Publish(ctx, "testch", []byte("hello world"))
43-
if err != nil {
46+
switch err {
47+
case nil:
48+
case context.Canceled:
49+
return
50+
default:
4451
t.Error(err)
4552
cancel()
4653
return
@@ -53,6 +60,13 @@ func (tp *TestSuite) TestBasicPubSub(t *testing.T) {
5360
}
5461
}()
5562

63+
// Wait for the sender to finish before we return.
64+
// Otherwise, we can get random errors as publish fails.
65+
defer func() {
66+
cancel()
67+
<-done
68+
}()
69+
5670
m, err := sub.Next(ctx)
5771
if err != nil {
5872
t.Fatal(err)

0 commit comments

Comments
 (0)