From 7172fda846c402ec3cb3606ca41f1d3e1e15e65b Mon Sep 17 00:00:00 2001 From: David Robertson Date: Thu, 19 Oct 2023 18:46:28 +0100 Subject: [PATCH 1/2] Stop waiting for data when closing v2 servers This makes integration tests about twice as fast for me, according to ```sh time go test -count=1 ./tests-integration/ -v ``` Before: real 2m4.053s user 0m4.187s sys 0m1.495s After: real 1m7.415s user 0m3.093s sys 0m1.347s --- tests-integration/v3_test.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/tests-integration/v3_test.go b/tests-integration/v3_test.go index 80ecaf5f..38b3a607 100644 --- a/tests-integration/v3_test.go +++ b/tests-integration/v3_test.go @@ -207,7 +207,13 @@ func (s *testV2Server) nextResponse(userID, token string) *sync2.SyncResponse { cond.Broadcast() } select { - case data := <-ch: + case data, stillOpen := <-ch: + if !stillOpen { + if !testutils.Quiet { + log.Printf("testV2Server: closing, returning null to %s %s", userID, token) + } + return nil + } if !testutils.Quiet { log.Printf( "testV2Server: nextResponse %s %s returning data: [invite=%d,join=%d,leave=%d]", @@ -228,6 +234,11 @@ func (s *testV2Server) url() string { } func (s *testV2Server) close() { + s.mu.Lock() + for _, ch := range s.queues { + close(ch) + } + s.mu.Unlock() s.srv.Close() } From c94670eea7c92dce933c4f932a9c8baf4a62fcfc Mon Sep 17 00:00:00 2001 From: David Robertson Date: Thu, 19 Oct 2023 18:58:17 +0100 Subject: [PATCH 2/2] Prevent a test from writing to a closed v2 server --- tests-integration/connection_test.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests-integration/connection_test.go b/tests-integration/connection_test.go index a0ab7ae1..d1143a2e 100644 --- a/tests-integration/connection_test.go +++ b/tests-integration/connection_test.go @@ -253,6 +253,7 @@ func TestConnectionTimeoutNotReset(t *testing.T) { } req.SetTimeoutMSecs(1000) // 1s // inject 4 events 500ms apart - if we reset the timeout each time then we will return late + done := make(chan struct{}) go func() { time.Sleep(10 * time.Millisecond) ticker := time.NewTicker(500 * time.Millisecond) @@ -277,6 +278,7 @@ func TestConnectionTimeoutNotReset(t *testing.T) { }) i++ } + done <- struct{}{} }() startTime := time.Now() res = v3.mustDoV3RequestWithPos(t, aliceToken, res.Pos, req) @@ -286,6 +288,8 @@ func TestConnectionTimeoutNotReset(t *testing.T) { } m.MatchResponse(t, res, m.MatchList("a", m.MatchV3Count(2)), m.MatchNoV3Ops()) + // Wait for all the responses before closing the v2 server. + <-done } // Test that the txn_id is echoed back