From c859164597cda7c5ab82388701133af6e5924e78 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Wed, 27 May 2020 18:24:17 +0100 Subject: [PATCH] Try to ensure that TestCorrectStreamWakeup doesn't block forever --- build/scripts/build-test-lint.sh | 2 +- syncapi/sync/notifier_test.go | 20 +++++++++++++------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/build/scripts/build-test-lint.sh b/build/scripts/build-test-lint.sh index d2b2b4b16..4b18ca2f8 100755 --- a/build/scripts/build-test-lint.sh +++ b/build/scripts/build-test-lint.sh @@ -13,4 +13,4 @@ go build ./cmd/... ./scripts/find-lint.sh echo "Testing..." -go test ./... +go test -v ./... diff --git a/syncapi/sync/notifier_test.go b/syncapi/sync/notifier_test.go index daed12754..e611e0276 100644 --- a/syncapi/sync/notifier_test.go +++ b/syncapi/sync/notifier_test.go @@ -160,14 +160,23 @@ func TestCorrectStreamWakeup(t *testing.T) { streamone := lockedFetchUserStream(n, alice, "one") streamtwo := lockedFetchUserStream(n, alice, "two") - go waitForBlocking(streamone, 1) - go waitForBlocking(streamtwo, 1) + wait := func(stream *UserDeviceStream) { + select { + case <-time.After(time.Second * 10): + return + default: + waitForBlocking(stream, 1) + } + } + + go wait(streamone) + go wait(streamtwo) go func() { select { - case <-n.userDeviceStreams[alice]["one"].signalChannel: + case <-streamone.signalChannel: awoken <- "one" - case <-n.userDeviceStreams[alice]["two"].signalChannel: + case <-streamtwo.signalChannel: awoken <- "two" } }() @@ -180,9 +189,6 @@ func TestCorrectStreamWakeup(t *testing.T) { if result := <-awoken; result != wake { t.Fatalf("expected to wake %q, got %q", wake, result) } - - close(n.userDeviceStreams[alice]["one"].signalChannel) - close(n.userDeviceStreams[alice]["two"].signalChannel) } // Test that an invite unblocks the request