Skip to content

Commit 9f38c57

Browse files
authored
test: fix hanging waitgroups (#699)
1 parent 34ce12e commit 9f38c57

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

_examples/profiling/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@ func main() {
4343
wg.Add(10)
4444
for i := 0; i < 10; i++ {
4545
go func(num int) {
46+
defer wg.Done()
4647
span := tx.StartChild(fmt.Sprintf("Goroutine %d", num))
4748
defer span.Finish()
4849
for i := 0; i < num; i++ {
4950
_ = findPrimeNumber(50000)
5051
runtime.Gosched() // we need to manually yield this busy loop
5152
}
5253
fmt.Printf("routine %d done\n", num)
53-
wg.Done()
5454
}(i)
5555
}
5656
wg.Wait()

transport_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -448,8 +448,6 @@ func TestHTTPTransport(t *testing.T) {
448448
}
449449
}
450450

451-
// Actual tests
452-
453451
testSendSingleEvent := func(t *testing.T) {
454452
// Sending a single event should increase the server event count by
455453
// exactly one.
@@ -467,6 +465,8 @@ func TestHTTPTransport(t *testing.T) {
467465
transportMustFlush(t, id)
468466
serverEventCountMustBe(t, initialCount+1)
469467
}
468+
469+
// Actual tests
470470
t.Run("SendSingleEvent", testSendSingleEvent)
471471

472472
t.Run("FlushMultipleTimes", func(t *testing.T) {
@@ -485,12 +485,12 @@ func TestHTTPTransport(t *testing.T) {
485485
var wg sync.WaitGroup
486486
wg.Add(2)
487487
go func() {
488+
defer wg.Done()
488489
testSendSingleEvent(t)
489-
wg.Done()
490490
}()
491491
go func() {
492+
defer wg.Done()
492493
transportMustFlush(t, "from goroutine")
493-
wg.Done()
494494
}()
495495
wg.Wait()
496496
})

0 commit comments

Comments
 (0)