Skip to content

Commit

Permalink
test: fix hanging waitgroups (#699)
Browse files Browse the repository at this point in the history
  • Loading branch information
vaind committed Aug 14, 2023
1 parent 34ce12e commit 9f38c57
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion _examples/profiling/main.go
Expand Up @@ -43,14 +43,14 @@ 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++ {
_ = findPrimeNumber(50000)
runtime.Gosched() // we need to manually yield this busy loop
}
fmt.Printf("routine %d done\n", num)
wg.Done()
}(i)
}
wg.Wait()
Expand Down
8 changes: 4 additions & 4 deletions transport_test.go
Expand Up @@ -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.
Expand All @@ -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) {
Expand All @@ -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()
})
Expand Down

0 comments on commit 9f38c57

Please sign in to comment.