mirror of
https://github.com/mjl-/mox.git
synced 2025-07-12 18:24:35 +03:00
fix race in test setup/teardown
not easily triggered, but it happened just now on a build server.
This commit is contained in:
@ -36,8 +36,7 @@ func TestMailbox(t *testing.T) {
|
||||
err = acc.Close()
|
||||
tcheck(t, err, "closing account")
|
||||
}()
|
||||
switchDone := Switchboard()
|
||||
defer close(switchDone)
|
||||
defer Switchboard()()
|
||||
|
||||
log := mlog.New("store")
|
||||
|
||||
|
@ -25,8 +25,7 @@ func TestExport(t *testing.T) {
|
||||
acc, err := OpenAccount("mjl")
|
||||
tcheck(t, err, "open account")
|
||||
defer acc.Close()
|
||||
switchDone := Switchboard()
|
||||
defer close(switchDone)
|
||||
defer Switchboard()()
|
||||
|
||||
log := mlog.New("export")
|
||||
|
||||
|
@ -101,7 +101,7 @@ type ChangeMailboxKeywords struct {
|
||||
var switchboardBusy atomic.Bool
|
||||
|
||||
// Switchboard distributes changes to accounts to interested listeners. See Comm and Change.
|
||||
func Switchboard() chan struct{} {
|
||||
func Switchboard() (stop func()) {
|
||||
regs := map[*Account]map[*Comm]struct{}{}
|
||||
done := make(chan struct{})
|
||||
|
||||
@ -145,14 +145,18 @@ func Switchboard() chan struct{} {
|
||||
chReq.done <- struct{}{}
|
||||
|
||||
case <-done:
|
||||
if !switchboardBusy.CompareAndSwap(true, false) {
|
||||
panic("switchboard already unregistered?")
|
||||
}
|
||||
done <- struct{}{}
|
||||
return
|
||||
}
|
||||
}
|
||||
}()
|
||||
return done
|
||||
return func() {
|
||||
done <- struct{}{}
|
||||
<-done
|
||||
if !switchboardBusy.CompareAndSwap(true, false) {
|
||||
panic("switchboard already unregistered?")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Comm handles communication with the goroutine that maintains the
|
||||
|
Reference in New Issue
Block a user