Skip to content

Commit

Permalink
Merge pull request #652 from strukturag/fix-proxy-config-test-race
Browse files Browse the repository at this point in the history
Fix race condition when accessing "expected" in proxy_config tests.
  • Loading branch information
fancycode authored Feb 7, 2024
2 parents a3ba73d + 48424bf commit d71ca35
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions proxy_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,26 +121,27 @@ func (p *mcuProxyForConfig) checkEvent(event *proxyConfigEvent) {
}
}

p.mu.Lock()
defer p.mu.Unlock()

if len(p.expected) == 0 {
p.t.Errorf("no event expected, got %+v from %s:%d", event, caller.File, caller.Line)
return
}

defer func() {
if len(p.expected) == 0 {
p.mu.Lock()
waiters := p.waiters
p.waiters = nil
p.mu.Unlock()
defer p.mu.Lock()

for _, ch := range waiters {
ch <- struct{}{}
}
}
}()

p.mu.Lock()
defer p.mu.Unlock()
expected := p.expected[0]
p.expected = p.expected[1:]
if !reflect.DeepEqual(expected, *event) {
Expand Down

0 comments on commit d71ca35

Please sign in to comment.