Commit d7528830 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 18a556b7
......@@ -140,6 +140,17 @@ func (m *_Msg) nak(why string) {
m.ack <- errors.New(why)
}
// nak represents scheduled call to `msg.nak(why)`.
type nak struct {
msg *_Msg
why string
}
// queuenak schedules call to `msg.nak(why)`.
func (t *T) queuenak(msg *_Msg, why string) {
t.nakq = append(t.nakq, nak{msg, why})
}
// newChan creates new _chan channel.
func (t *T) newChan(name string) *_chan {
// NOTE T ensures not to create channels with duplicate names.
......
......@@ -155,11 +155,6 @@ type delayInjectState struct {
delayT time.Duration // by delayT time.
}
type nak struct {
msg *_Msg
why string
}
// SetEventRouter tells t to which stream an event should go.
//
......@@ -221,7 +216,20 @@ func (t *T) RxEvent(event interface{}) {
// xget1 gets 1 event in place and checks it has expected type
//
// if checks do not pass - fatal testing error is raised
func (t *T) xget1(stream string, eventp interface{}) *_Msg {
t.Helper()
t.mu.Lock()
ch := t.chanForStream(stream)
t.mu.Unlock()
// XXX ch == nil -> no longer operational
return ch.RecvInto(eventp)
}
......@@ -230,20 +238,7 @@ func (t *T) RxEvent(event interface{}) {
// chanForStream returns channel corresponding to stream.
// must be called under mu.
func (t *T) chanForStream(stream string) *_chan {
if t.streamTab == nil {
return nil // t is no longer operational after e.g. deadlock
}
ch, ok := t.streamTab[stream]
if !ok {
ch = t.newChan(stream)
t.streamTab[stream] = ch
}
return ch
}
// Expect receives next event on stream and verifies it to be equal to eventOK.
//
......@@ -286,21 +281,6 @@ func (t *T) expect1(stream string, eventExpect interface{}) *_Msg {
return msg
}
// xget1 gets 1 event in place and checks it has expected type
//
// if checks do not pass - fatal testing error is raised
func (t *T) xget1(stream string, eventp interface{}) *_Msg {
t.Helper()
t.mu.Lock()
ch := t.chanForStream(stream)
t.mu.Unlock()
// XXX ch == nil -> no longer operational
return ch.RecvInto(eventp)
}
// fatalfInNonMain should be called for fatal cases in non-main goroutines instead of panic.
//
// we don't panic because it will stop the process and prevent the main
......@@ -515,6 +495,21 @@ func Verify(t *testing.T, f func(t *T)) {
}
}
// chanForStream returns channel corresponding to stream.
// must be called under mu.
func (t *T) chanForStream(stream string) *_chan {
if t.streamTab == nil {
return nil // t is no longer operational after e.g. deadlock
}
ch, ok := t.streamTab[stream]
if !ok {
ch = t.newChan(stream)
t.streamTab[stream] = ch
}
return ch
}
// streamsOfTrace returns sorted list of all streams present in a trace.
func streamsOfTrace(tracev []eventTrace) []string {
......@@ -529,9 +524,3 @@ func streamsOfTrace(tracev []eventTrace) []string {
sort.Strings(streamv)
return streamv
}
// XXX place; just use t.Cleanup instead?
func (t *T) queuenak(msg *_Msg, why string) {
t.nakq = append(t.nakq, nak{msg, why})
}
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