Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: fix hanging waitgroups #699

Merged
merged 1 commit into from
Aug 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion _examples/profiling/main.go
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Loading