Fix race condition when accessing "expected" in proxy_config tests.

This commit is contained in:
Joachim Bauch 2024-02-07 10:00:15 +01:00
parent 9da78a1a8b
commit 48424bf290
No known key found for this signature in database
GPG key ID: 77C1D22D53E15F02

View file

@ -121,6 +121,9 @@ 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
@ -128,10 +131,10 @@ func (p *mcuProxyForConfig) checkEvent(event *proxyConfigEvent) {
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{}{}
@ -139,8 +142,6 @@ func (p *mcuProxyForConfig) checkEvent(event *proxyConfigEvent) {
}
}()
p.mu.Lock()
defer p.mu.Unlock()
expected := p.expected[0]
p.expected = p.expected[1:]
if !reflect.DeepEqual(expected, *event) {