Commit 00de46e2 authored by Steven Allen's avatar Steven Allen

fix(test): fix a flaky pubsub test

parent 10d20732
...@@ -34,13 +34,20 @@ func (tp *TestSuite) TestBasicPubSub(t *testing.T) { ...@@ -34,13 +34,20 @@ func (tp *TestSuite) TestBasicPubSub(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
done := make(chan struct{})
go func() { go func() {
defer close(done)
ticker := time.NewTicker(100 * time.Millisecond) ticker := time.NewTicker(100 * time.Millisecond)
defer ticker.Stop() defer ticker.Stop()
for { for {
err := apis[1].PubSub().Publish(ctx, "testch", []byte("hello world")) 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) t.Error(err)
cancel() cancel()
return return
...@@ -53,6 +60,13 @@ func (tp *TestSuite) TestBasicPubSub(t *testing.T) { ...@@ -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) m, err := sub.Next(ctx)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment