From 6f0b11789a8dd33b64e20c6430a373a1aa4f2f70 Mon Sep 17 00:00:00 2001 From: Lautaro Emanuel Date: Fri, 31 May 2024 16:47:42 -0300 Subject: [PATCH] Test `SafeSubscription` concurrent unsubscribe --- core/safeclient/client_test.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/core/safeclient/client_test.go b/core/safeclient/client_test.go index 3b74a3e1..f462a7d8 100644 --- a/core/safeclient/client_test.go +++ b/core/safeclient/client_test.go @@ -679,3 +679,21 @@ func TestSubscribeFilterLogs_ErrorInSubscription_Resubscribe(t *testing.T) { triggerError() } + +func TestSafeSubscription_ConcurrentUnsubscribe(t *testing.T) { + mockCtrl := gomock.NewController(t) + sub := mocks.NewMockSubscription(mockCtrl) + sub.EXPECT().Unsubscribe().Times(1) + + safeSub := safeclient.NewSafeSubscription(sub) + + var wg sync.WaitGroup + for i := 1; i <= 10; i++ { + wg.Add(1) + go func() { + defer wg.Done() + safeSub.Unsubscribe() + }() + } + wg.Wait() +}