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

.

parent b74bca96
......@@ -87,24 +87,26 @@ func routeEvent(event interface{}) (stream string) {
return strings.ToLower(who[:i])
}
// setupTraceEvents sets up tracing and routing.
// it is used in the prologue of tests.
func setupTraceEvents(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)
// 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)
})
}
// TestExample demonstrates how to use tracetest to verify concurrent system with 2 threads.
func TestExample(t *testing.T) {
tracetest.Verify(t, func(t *tracetest.T) {
// setup tracing to deliver trace events to t and route them appropriately.
setupTraceEvents(t)
// run the workload
// Test2ThreadsOK demonstrates verifying 2 threads that execute independently.
// There is no concurreny problem here.
func Test2ThreadsOK(t *testing.T) {
verify(t, func(t *tracetest.T) {
var wg sync.WaitGroup
defer wg.Wait()
wg.Add(2)
......@@ -117,11 +119,14 @@ func TestExample(t *testing.T) {
go func() { // thread2
defer wg.Done()
hi("T2·C")
hello("T2·C")
hi("T2·D")
}()
// assert that events come as expected
t.Expect("t2", eventHi("T2·C"))
// in checks t2 vs t1 order does not matter
t.Expect("t2", eventHello("T2·C"))
t.Expect("t2", eventHi("T2·D"))
t.Expect("t1", eventHi("T1·A"))
t.Expect("t1", eventHello("T1·B"))
......@@ -131,3 +136,10 @@ func TestExample(t *testing.T) {
//t1.Expect(eventHi("X·A"))
})
}
// XXX
func TestDeadlock(t *testing.T) {
verify(t, func(t *tracetest.T) {
})
}
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