diff --git a/go/internal/xtracing/tracetest/tracetest.go b/go/internal/xtracing/tracetest/tracetest.go index d1828db43eae93d325ab7f11873620309a346eeb..604b83a0f4da835a1f26d035350070b166666bb4 100644 --- a/go/internal/xtracing/tracetest/tracetest.go +++ b/go/internal/xtracing/tracetest/tracetest.go @@ -843,6 +843,7 @@ func Verify(t *testing.T, f func(t *T)) { if len(trace0) < 2 { return } + streams0 := streamsOfTrace(trace0) // sort trace0 by time just in case - events migth come from multiple // CPUs simultaneously, and so for close events they might be added to @@ -860,7 +861,7 @@ func Verify(t *testing.T, f func(t *T)) { } } - // retest f with 10路未tMax injected at i'th event + // retest f with 10路未tMax delay injected at i'th event XXX 10x is too much? for i := 0; i < len(trace0); i++ { // stream and on-stream sequence number for i'th global event stream := trace0[i].stream @@ -875,22 +876,37 @@ func Verify(t *testing.T, f func(t *T)) { tT := testf(t, map[string]*delayInjectState{ stream: &delayInjectState{ delayAt: istream, - delayT: 10*未tMax, // XXX make sure it < deadTime + delayT: 10*未tMax, // TODO make sure it < deadTime }, }) - // XXX in the end: verify that streams are the same from run to run (if completed successfully). - _ = tT + // verify that streams are the same from run to run + if tT.Failed() { + return + } + streams := streamsOfTrace(tT.tracev) + fmt.Printf("streams0: %v\n", streams0) + fmt.Printf("streams: %v\n", streams) + if !reflect.DeepEqual(streams, streams0) { + tT.Fatalf("streams are not the same as in the first run:\n"+ + "first: %s\nnow: %s\ndiff:\n%s\n\n", + streams0, streams, pretty.Compare(streams0, streams)) + } }) - } } -/* -// ---- misc ---- - -func panicf(format string, argv ...interface{}) { - panic(fmt.Sprintf(format, argv...)) +// streamsOfTrace returns sorted list of all streams present in a trace. +func streamsOfTrace(tracev []eventTrace) []string { + streams := make(map[string]struct{}) + for _, t := range tracev { + streams[t.stream] = struct{}{} + } + streamv := []string{} + for stream := range streams { + streamv = append(streamv, stream) + } + sort.Strings(streamv) + return streamv } -*/