From 7c8e7857faea075c15ba5af612193c6dda5a330a Mon Sep 17 00:00:00 2001 From: vyzo Date: Tue, 21 Apr 2020 09:45:52 +0300 Subject: [PATCH] deflake TestValidatorOverload reguarly fails on travis with successful validation; the timings were just wrong. --- floodsub_test.go | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/floodsub_test.go b/floodsub_test.go index 270d520..b398b81 100644 --- a/floodsub_test.go +++ b/floodsub_test.go @@ -519,7 +519,7 @@ func TestValidateOverload(t *testing.T) { t.Log(msg) t.Error("expected message validation to drop the message because all validator goroutines are taken") } - case <-time.After(333 * time.Millisecond): + case <-time.After(time.Second): if tmsg.validates { t.Error("expected message validation to accept the message") } @@ -528,20 +528,17 @@ func TestValidateOverload(t *testing.T) { wg.Done() }() - for i, tmsg := range tc.msgs { + for _, tmsg := range tc.msgs { err := p.Publish(topic, tmsg.msg) if err != nil { t.Fatal(err) } - - // wait a bit to let pubsub's internal state machine start validating the message - time.Sleep(10 * time.Millisecond) - - // unblock validator goroutines after we sent one too many - if i == len(tc.msgs)-1 { - close(block) - } } + + // wait a bit before unblocking the validator goroutines + time.Sleep(500 * time.Millisecond) + close(block) + wg.Wait() } }