Skip to content

Commit

Permalink
Fix the race condition in the test code.
Browse files Browse the repository at this point in the history
  • Loading branch information
schmidtw committed Mar 18, 2024
1 parent c5dcd52 commit a8c7451
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion internal/pubsub/end2end_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ var messages = []msgWithExpectations{
}

type mockHandler struct {
lock sync.Mutex
wg *sync.WaitGroup
name string
calls int
Expand All @@ -92,14 +93,20 @@ func (h *mockHandler) WG(wg *sync.WaitGroup) {
}

func (h *mockHandler) HandleWrp(msg wrp.Message) {
h.lock.Lock()
defer h.lock.Unlock()

h.calls++
dest, _ := wrp.ParseLocator(msg.Destination)
h.dests = append(h.dests, dest)
h.wg.Done()
//fmt.Printf("%s done\n", h.name)
}

func (h mockHandler) assert(a *assert.Assertions) {
func (h *mockHandler) assert(a *assert.Assertions) {
h.lock.Lock()
defer h.lock.Unlock()

if !a.Equal(len(h.expect), h.calls, "handler %s calls mismatch", h.name) {
return
}
Expand Down

0 comments on commit a8c7451

Please sign in to comment.