Commit aa64f2b3 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent ae125f96
......@@ -636,7 +636,6 @@ func (t *T) xget1(stream string, eventp interface{}) *Msg {
// ok
case <-time.After(*deadTime):
//t.deadlock(stream, eventp)
t.Fatalf("%s: recv: deadlock waiting for %T\n", stream, eventp)
}
......@@ -673,6 +672,26 @@ func (t *T) fatalfInNonMain(format string, argv ...interface{}) {
// T overrides FailNow/Fatal/Fatalf to also cancel all in-progress sends.
func (t *T) FailNow() {
t.Helper()
_ = t.closeStreamTab()
t.TB.FailNow()
}
func (t *T) Fatal(argv ...interface{}) {
t.Helper()
t.Log(argv...)
t.FailNow()
}
func (t *T) Fatalf(format string, argv ...interface{}) {
t.Helper()
t.Logf(format, argv...)
t.FailNow()
}
// closeStreamTab prints details about pending event on streamTab, naks them
// and closes all channels. It returns the number of naked messages.
func (t *T) closeStreamTab() (nnak int) {
t.Helper()
// mark streamTab no longer operational
t.streamTabMu.Lock()
......@@ -680,6 +699,10 @@ func (t *T) FailNow() {
t.streamTab = nil
t.streamTabMu.Unlock()
if streamTab == nil {
return // already closed
}
// print details about pending events and all streams
type sendInfo struct{ch Chan; msg *Msg}
var sendv []sendInfo // sends are pending here
......@@ -719,27 +742,19 @@ func (t *T) FailNow() {
t.Log(pending)
for _, __ := range t.nakq {
__.msg.nak(__.why)
nnak++
}
t.nakq = nil
for _, __ := range sendv {
__.msg.nak("canceled (test failed)")
nnak++
}
// in any case close channel where future Sends may arrive so that they will "panic" too.
for _, ch := range streamTab {
ch.Close()
}
t.TB.FailNow()
}
func (t *T) Fatal(argv ...interface{}) {
t.Helper()
t.Log(argv...)
t.FailNow()
}
func (t *T) Fatalf(format string, argv ...interface{}) {
t.Helper()
t.Logf(format, argv...)
t.FailNow()
return nnak
}
......@@ -759,13 +774,17 @@ func Verify(t testing.TB, f func(t *T)) {
tT := &T{TB: t, streamTab: make(map[string]Chan)}
// XXX
// XXX not here
/*
// verify in the end that no events are left unchecked / unconsumed
// (e.g. sent to RxEvent, but not received). Nak them if they are ... XXX
// verify in the end that no events are left unchecked / unconsumed,
// e.g. sent to RxEvent, but not received. Nak them if they are and fail.
//
// NOTE this complements T.Fatal and friends, because a test might
// think it completes successfully, but leaves unconsumed events behind it.
defer func() {
nnak := tT.closeStreamTab()
if nnak != 0 {
t.Fatal()
}
}()
*/
f(tT)
......
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