Skip to content

Commit

Permalink
Fix race condition in test (#55)
Browse files Browse the repository at this point in the history
Resolves #53

🤔 interesting. It was not causing any problems on my box. I was using Go
go1.21.5 + go1.21.6 darwin/arm64.
Only when I added a `time.Sleep(time.Millisecond)` before the second
`startTogether` call, I can reproduce the issue.
Sorry for this. 

I found a similar scenario on
[stackoverflow](https://stackoverflow.com/questions/39800700/waitgroup-is-reused-before-previous-wait-has-returned)
that helped to resolve the issue.
  • Loading branch information
alpe authored Jan 12, 2024
1 parent cbfa863 commit 8c38144
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pkg/endpoints/endpoints_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ func TestConcurrentAccess(t *testing.T) {
)

var startWg, doneWg sync.WaitGroup
startWg.Add(spec.readerCount + spec.writerCount)
doneWg.Add(spec.readerCount + spec.writerCount)
startTogether := func(n int, f func()) {
startWg.Add(n)
doneWg.Add(n)
for i := 0; i < n; i++ {
go func() {
startWg.Done()
Expand Down

0 comments on commit 8c38144

Please sign in to comment.