Commit 4afad355 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 4a44c0a0
......@@ -26,6 +26,8 @@ package tracetest_test
import (
"fmt"
"os"
"os/exec"
"strings"
"sync"
"testing"
......@@ -87,19 +89,41 @@ func routeEvent(event interface{}) (stream string) {
return strings.ToLower(who[:i])
}
// verify calls tracetest.Verify on f with first preparing tracing setup and event delivery.
// It also verifies that tracetest catches errors as expected. // TODO
func verify(t *testing.T, f func(t *tracetest.T)) {
tracetest.Verify(t, func(t *tracetest.T) {
// setup tracing to deliver trace events to t.
pg := setupTracing(t)
t.Cleanup(pg.Done)
// tell t to which stream an event should go.
t.SetEventRouter(routeEvent)
// run test code
f(t)
})
// verify calls tracetest.Verify on f with first preparing tracing setup and events delivery.
// It also verifies that tracetest detects errors as expected.
func verify(t *testing.T, f func(t *tracetest.T), targvExtra ...string) {
if os.Getenv("TRACETEST_EX_VERIFY_IN_SUBPROCESS") == "1" {
tracetest.Verify(t, func(t *tracetest.T) {
// setup tracing to deliver trace events to t.
pg := setupTracing(t)
t.Cleanup(pg.Done)
// tell t to which stream an event should go.
t.SetEventRouter(routeEvent)
// run test code
f(t)
})
return
}
// spawn the test in subprocess and verify its output
outOK, ok := testExpect[t.Name()]
if !ok {
panic(fmt.Sprintf("testExpect[%q] not defined", t.Name()))
}
argv := []string{"-test.run="+t.Name()}
argv = append(argv, targvExtra...)
cmd := exec.Command(os.Args[0], argv...)
cmd.Env = append(os.Environ(), "TRACETEST_EX_VERIFY_IN_SUBPROCESS=1")
bout, err := cmd.CombinedOutput()
out := string(bout)
if err != nil {
t.Log(out)
t.Fatal(err) // XXX check first it is not "exit code"
}
// XXX verify out
_ = outOK
}
......@@ -158,5 +182,32 @@ func TestDeadlock(t *testing.T) {
// the checker expects something on stream "t3", but there is
// no event sent there -> deadlock.
t.Expect("t3", eventHi("zzz"))
})
}, "-tracetest.deadtime=0.5s")
}
// XXX race bug with sleep caught only by delay injection
// --------
// testExpect maps <test name> -> expected output
var testExpect = map[string]string{
"Test2ThreadsOK": "",
"TestDeadlock": `
--- FAIL: TestDeadlock (.+s)
example_test.go:179: t3: recv: deadlock waiting for *tracetest_test.eventHi
example_test.go:179: test shutdown: #streams: 3, #(pending events): 2
t1 <- tracetest_test.eventHi T1·A
t2 <- tracetest_test.eventHi T2·B
# t3
tracetest.go:175: t2: send: canceled (test failed)
.*
tracetest.go:175: t1: send: canceled (test failed)
.*
FAIL
exit status 1
`,
}
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