Commit 5a3f6a12 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent f15263d9
...@@ -140,6 +140,7 @@ func Test2ThreadsOK(t *testing.T) { ...@@ -140,6 +140,7 @@ func Test2ThreadsOK(t *testing.T) {
} }
// TestDeadlock demonstrates deadlock detection. // TestDeadlock demonstrates deadlock detection.
// XXX also test for wrong decomposition XXX or is it also covered by this test as well?
func TestDeadlock(t *testing.T) { func TestDeadlock(t *testing.T) {
verify(t, func(t *tracetest.T) { verify(t, func(t *tracetest.T) {
var wg sync.WaitGroup var wg sync.WaitGroup
...@@ -296,8 +297,8 @@ var testExpectMap = map[string]testExpect{ ...@@ -296,8 +297,8 @@ var testExpectMap = map[string]testExpect{
"TestDeadlock": {1, "TestDeadlock": {1,
`--- FAIL: TestDeadlock (<TIME>) `--- FAIL: TestDeadlock (<TIME>)
example_test.go:156: t2: recv: deadlock waiting for *tracetest_test.eventHi example_test.go:157: t2: recv: deadlock waiting for *tracetest_test.eventHi
example_test.go:156: test shutdown: #streams: 2, #(pending events): 1 example_test.go:157: test shutdown: #streams: 2, #(pending events): 1
t1 <- tracetest_test.eventHi T1·A t1 <- tracetest_test.eventHi T1·A
# t2 # t2
...@@ -306,7 +307,7 @@ var testExpectMap = map[string]testExpect{ ...@@ -306,7 +307,7 @@ var testExpectMap = map[string]testExpect{
"TestRace": {1, "TestRace": {1,
` --- FAIL: TestRace/delay@0(=x:0) (<TIME>) ` --- FAIL: TestRace/delay@0(=x:0) (<TIME>)
example_test.go:182: x: expect: tracetest_test.eventHi: example_test.go:183: x: expect: tracetest_test.eventHi:
want: x·A want: x·A
have: x·B have: x·B
diff: diff:
...@@ -316,8 +317,8 @@ var testExpectMap = map[string]testExpect{ ...@@ -316,8 +317,8 @@ var testExpectMap = map[string]testExpect{
"TestExpectType": {1, "TestExpectType": {1,
`--- FAIL: TestExpectType (<TIME>) `--- FAIL: TestExpectType (<TIME>)
example_test.go:202: t1: expect: tracetest_test.eventHello: got tracetest_test.eventHi T1·A example_test.go:203: t1: expect: tracetest_test.eventHello: got tracetest_test.eventHi T1·A
example_test.go:202: test shutdown: #streams: 1, #(pending events): 0 example_test.go:203: test shutdown: #streams: 1, #(pending events): 0
# t1 # t1
tracetest.go:<LINE>: t1: send: unexpected event type tracetest.go:<LINE>: t1: send: unexpected event type
...@@ -325,14 +326,14 @@ var testExpectMap = map[string]testExpect{ ...@@ -325,14 +326,14 @@ var testExpectMap = map[string]testExpect{
"TestExpectValue": {1, "TestExpectValue": {1,
`--- FAIL: TestExpectValue (<TIME>) `--- FAIL: TestExpectValue (<TIME>)
example_test.go:218: t1: expect: tracetest_test.eventHi: example_test.go:219: t1: expect: tracetest_test.eventHi:
want: T1·B want: T1·B
have: T1·A have: T1·A
diff: diff:
-"T1·B" -"T1·B"
+"T1·A" +"T1·A"
example_test.go:218: test shutdown: #streams: 1, #(pending events): 0 example_test.go:219: test shutdown: #streams: 1, #(pending events): 0
# t1 # t1
tracetest.go:<LINE>: t1: send: unexpected event data tracetest.go:<LINE>: t1: send: unexpected event data
......
...@@ -99,6 +99,8 @@ var ( ...@@ -99,6 +99,8 @@ var (
deadTime = flag.Duration("tracetest.deadtime", 3*time.Second, "time after which no events activity is considered to be a deadlock") deadTime = flag.Duration("tracetest.deadtime", 3*time.Second, "time after which no events activity is considered to be a deadlock")
) )
// XXX hide Chan from public API
// Chan provides synchronous channel with additional property that send // Chan provides synchronous channel with additional property that send
// blocks until receiving side explicitly acknowledges message was received and // blocks until receiving side explicitly acknowledges message was received and
// processed. // processed.
...@@ -529,6 +531,7 @@ func (t *T) queuenak(msg *Msg, why string) { ...@@ -529,6 +531,7 @@ func (t *T) queuenak(msg *Msg, why string) {
// XXX doc; naming // XXX doc; naming
// XXX document routeEvent requirements
func (t *T) SetEventRouter(routeEvent func(event interface{}) (stream string)) { func (t *T) SetEventRouter(routeEvent func(event interface{}) (stream string)) {
t.mu.Lock() t.mu.Lock()
defer t.mu.Unlock() defer t.mu.Unlock()
...@@ -544,11 +547,14 @@ func (t *T) SetEventRouter(routeEvent func(event interface{}) (stream string)) { ...@@ -544,11 +547,14 @@ func (t *T) SetEventRouter(routeEvent func(event interface{}) (stream string)) {
// XXX pass events in not via t (via something dedicated)? // XXX pass events in not via t (via something dedicated)?
func (t *T) RxEvent(event interface{}) { func (t *T) RxEvent(event interface{}) {
t0 := time.Now() t0 := time.Now()
stream := "default" stream := ""
t.mu.Lock() t.mu.Lock()
if t.routeEvent != nil { if t.routeEvent != nil {
stream = t.routeEvent(event) stream = t.routeEvent(event)
} }
if stream == "" {
stream = "default"
}
t.tracev = append(t.tracev, eventTrace{t0, stream, event}) t.tracev = append(t.tracev, eventTrace{t0, stream, event})
ch := t.chanForStream(stream) ch := t.chanForStream(stream)
...@@ -885,8 +891,6 @@ func Verify(t *testing.T, f func(t *T)) { ...@@ -885,8 +891,6 @@ func Verify(t *testing.T, f func(t *T)) {
return return
} }
streams := streamsOfTrace(tT.tracev) streams := streamsOfTrace(tT.tracev)
fmt.Printf("streams0: %v\n", streams0)
fmt.Printf("streams: %v\n", streams)
if !reflect.DeepEqual(streams, streams0) { if !reflect.DeepEqual(streams, streams0) {
tT.Fatalf("streams are not the same as in the first run:\n"+ tT.Fatalf("streams are not the same as in the first run:\n"+
"first: %s\nnow: %s\ndiff:\n%s\n\n", "first: %s\nnow: %s\ndiff:\n%s\n\n",
......
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