From 5cfae4c1d48a16f9c2a387603f182683cdbea033 Mon Sep 17 00:00:00 2001 From: Filip Petkovski Date: Wed, 28 Aug 2024 09:42:13 +0200 Subject: [PATCH] Remove lock Signed-off-by: Filip Petkovski --- pkg/receive/handler_test.go | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/pkg/receive/handler_test.go b/pkg/receive/handler_test.go index 8c13792cb1..efee79a861 100644 --- a/pkg/receive/handler_test.go +++ b/pkg/receive/handler_test.go @@ -221,7 +221,6 @@ func newTestHandlerHashring( } var ( - mu sync.Mutex closers = make([]func() error, 0) ag = addrGen{} @@ -252,17 +251,12 @@ func newTestHandlerHashring( srv := NewCapNProtoServer(listener, handler) client := writecapnp.NewRemoteWriteClient(listener) peer = newPeerWorker(client, prometheus.NewHistogram(prometheus.HistogramOpts{}), 1) - go func() { - mu.Lock() - closers = append(closers, func() error { - srv.Shutdown() - peer.wp.Close() - return goerrors.Join(listener.Close(), client.Close()) - }) - mu.Unlock() - - _ = srv.ListenAndServe() - }() + closers = append(closers, func() error { + srv.Shutdown() + peer.wp.Close() + return goerrors.Join(listener.Close(), client.Close()) + }) + go func() { _ = srv.ListenAndServe() }() fakePeers.clients[endpoint] = peer } else { peer = newPeerWorker(&fakeRemoteWriteGRPCServer{h: h}, prometheus.NewHistogram(prometheus.HistogramOpts{}), 1) @@ -662,7 +656,7 @@ func testReceiveQuorum(t *testing.T, hashringAlgo HashringAlgorithm, withConsist }, }, } { - t.Run(fmt.Sprintf("%s/%s=%t", tc.name, "capnp-replication", capnpReplication), func(t *testing.T) { + t.Run(tc.name, func(t *testing.T) { handlers, hashring, closeFunc, err := newTestHandlerHashring(tc.appendables, tc.replicationFactor, hashringAlgo, capnpReplication) if err != nil { t.Fatalf("unable to create test handler: %v", err) @@ -743,25 +737,33 @@ func testReceiveQuorum(t *testing.T, hashringAlgo HashringAlgorithm, withConsist func TestReceiveQuorumHashmod(t *testing.T) { for _, capnpReplication := range []bool{false, true} { - testReceiveQuorum(t, AlgorithmHashmod, false, capnpReplication) + t.Run(fmt.Sprintf("capnproto-replication=%t", capnpReplication), func(t *testing.T) { + testReceiveQuorum(t, AlgorithmHashmod, false, capnpReplication) + }) } } func TestReceiveQuorumKetama(t *testing.T) { for _, capnpReplication := range []bool{false, true} { - testReceiveQuorum(t, AlgorithmKetama, false, capnpReplication) + t.Run(fmt.Sprintf("capnproto-replication=%t", capnpReplication), func(t *testing.T) { + testReceiveQuorum(t, AlgorithmKetama, false, capnpReplication) + }) } } func TestReceiveWithConsistencyDelayHashmod(t *testing.T) { for _, capnpReplication := range []bool{false, true} { - testReceiveQuorum(t, AlgorithmHashmod, true, capnpReplication) + t.Run(fmt.Sprintf("capnproto-replication=%t", capnpReplication), func(t *testing.T) { + testReceiveQuorum(t, AlgorithmHashmod, true, capnpReplication) + }) } } func TestReceiveWithConsistencyDelayKetama(t *testing.T) { for _, capnpReplication := range []bool{false, true} { - testReceiveQuorum(t, AlgorithmKetama, true, capnpReplication) + t.Run(fmt.Sprintf("capnproto-replication=%t", capnpReplication), func(t *testing.T) { + testReceiveQuorum(t, AlgorithmKetama, true, capnpReplication) + }) } }