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