From 9f38c571d6236f2d0f684221bdaf42d4e6ef0e82 Mon Sep 17 00:00:00 2001 From: Ivan Dlugos <6349682+vaind@users.noreply.github.com> Date: Mon, 14 Aug 2023 14:35:50 +0200 Subject: [PATCH] test: fix hanging waitgroups (#699) --- _examples/profiling/main.go | 2 +- transport_test.go | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/_examples/profiling/main.go b/_examples/profiling/main.go index c1dc69e1a..5f33ce9c3 100644 --- a/_examples/profiling/main.go +++ b/_examples/profiling/main.go @@ -43,6 +43,7 @@ func main() { wg.Add(10) for i := 0; i < 10; i++ { go func(num int) { + defer wg.Done() span := tx.StartChild(fmt.Sprintf("Goroutine %d", num)) defer span.Finish() for i := 0; i < num; i++ { @@ -50,7 +51,6 @@ func main() { runtime.Gosched() // we need to manually yield this busy loop } fmt.Printf("routine %d done\n", num) - wg.Done() }(i) } wg.Wait() diff --git a/transport_test.go b/transport_test.go index f29055b49..c0965b82e 100644 --- a/transport_test.go +++ b/transport_test.go @@ -448,8 +448,6 @@ func TestHTTPTransport(t *testing.T) { } } - // Actual tests - testSendSingleEvent := func(t *testing.T) { // Sending a single event should increase the server event count by // exactly one. @@ -467,6 +465,8 @@ func TestHTTPTransport(t *testing.T) { transportMustFlush(t, id) serverEventCountMustBe(t, initialCount+1) } + + // Actual tests t.Run("SendSingleEvent", testSendSingleEvent) t.Run("FlushMultipleTimes", func(t *testing.T) { @@ -485,12 +485,12 @@ func TestHTTPTransport(t *testing.T) { var wg sync.WaitGroup wg.Add(2) go func() { + defer wg.Done() testSendSingleEvent(t) - wg.Done() }() go func() { + defer wg.Done() transportMustFlush(t, "from goroutine") - wg.Done() }() wg.Wait() })