Commit 4679e521 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 0853555b
...@@ -152,6 +152,7 @@ type Msg struct { ...@@ -152,6 +152,7 @@ type Msg struct {
type _chan struct { type _chan struct {
t *T t *T
msgq chan *Msg msgq chan *Msg
down chan struct{} // becomes ready when closed
_name string _name string
} }
...@@ -166,16 +167,21 @@ func (ch *_chan) Send(event interface{}) { ...@@ -166,16 +167,21 @@ func (ch *_chan) Send(event interface{}) {
fmt.Printf("%s <- %T %v\n", ch.name(), event, event) fmt.Printf("%s <- %T %v\n", ch.name(), event, event)
} }
ack := make(chan error) ack := make(chan error)
ch.msgq <- &Msg{event, ack} select {
err := <-ack case <-ch.down:
if err != nil { ch.t.fatalfInNonMain("%s: send: channel was closed", ch.name())
ch.t.fatalfInNonMain("%s: send: %s", ch.name(), err)
case ch.msgq <- &Msg{event, ack}:
err := <-ack
if err != nil {
ch.t.fatalfInNonMain("%s: send: %s", ch.name(), err)
}
} }
} }
// Close implements ChanTx. // Close implements ChanTx.
func (ch *_chan) Close() { func (ch *_chan) Close() {
close(ch.msgq) close(ch.down) // note - not .msgq
} }
// Recv implements ChanRx. // Recv implements ChanRx.
...@@ -732,9 +738,6 @@ func (t *T) FailNow() { ...@@ -732,9 +738,6 @@ func (t *T) FailNow() {
default: default:
} }
// in any case close channel where future Sends may arrive so that will panic too.
ch.Close()
} }
// order channels by name // order channels by name
...@@ -752,13 +755,17 @@ func (t *T) FailNow() { ...@@ -752,13 +755,17 @@ func (t *T) FailNow() {
} }
} }
// log the deadlock details and nak all senders. // log the deadlock details and nak senders that we received from.
// nak them only after deadlock printout, so that the deadlock text // nak them only after deadlock printout, so that the deadlock text
// comes first, and their "panics" don't get intermixed with it. // comes first, and their "panics" don't get intermixed with it.
t.Log(bad) t.Log(bad)
for _, __ := range sendv { for _, __ := range sendv {
__.msg.nak("XXX deadlock") // XXX reason can be custom / different __.msg.nak("XXX deadlock") // XXX reason can be custom / different
} }
// in any case close channel where future Sends may arrive so that will "panic" too.
for _, ch := range streamTab {
ch.Close()
}
t.TB.FailNow() t.TB.FailNow()
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment