mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-28 22:08:01 +08:00
Merge pull request ipfs/boxoipfs/interface-go-ipfs-core#45 from ipfs/fix/flaky-pubsub-test
fix(test): fix a flaky pubsub test This commit was moved from ipfs/interface-go-ipfs-core@1c94e62171 This commit was moved from ipfs/boxo@57d800d8f6
This commit is contained in:
commit
d3598ca21b
@ -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
|
||||
@ -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)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user