|
@ -33,7 +33,7 @@ func TestRoutineFinal(t *testing.T) { |
|
|
assert.True(t, routine.isRunning(), |
|
|
assert.True(t, routine.isRunning(), |
|
|
"expected an started routine") |
|
|
"expected an started routine") |
|
|
|
|
|
|
|
|
assert.True(t, routine.trySend(eventA{}), |
|
|
|
|
|
|
|
|
assert.True(t, routine.send(eventA{}), |
|
|
"expected sending to a ready routine to succeed") |
|
|
"expected sending to a ready routine to succeed") |
|
|
|
|
|
|
|
|
assert.Equal(t, done, <-routine.final(), |
|
|
assert.Equal(t, done, <-routine.final(), |
|
@ -46,18 +46,18 @@ func TestRoutineFinal(t *testing.T) { |
|
|
func TestRoutineStop(t *testing.T) { |
|
|
func TestRoutineStop(t *testing.T) { |
|
|
routine := newRoutine("simpleRoutine", simpleHandler) |
|
|
routine := newRoutine("simpleRoutine", simpleHandler) |
|
|
|
|
|
|
|
|
assert.False(t, routine.trySend(eventA{}), |
|
|
|
|
|
|
|
|
assert.False(t, routine.send(eventA{}), |
|
|
"expected sending to an unstarted routine to fail") |
|
|
"expected sending to an unstarted routine to fail") |
|
|
|
|
|
|
|
|
go routine.start() |
|
|
go routine.start() |
|
|
<-routine.ready() |
|
|
<-routine.ready() |
|
|
|
|
|
|
|
|
assert.True(t, routine.trySend(eventA{}), |
|
|
|
|
|
|
|
|
assert.True(t, routine.send(eventA{}), |
|
|
"expected sending to a running routine to succeed") |
|
|
"expected sending to a running routine to succeed") |
|
|
|
|
|
|
|
|
routine.stop() |
|
|
routine.stop() |
|
|
|
|
|
|
|
|
assert.False(t, routine.trySend(eventA{}), |
|
|
|
|
|
|
|
|
assert.False(t, routine.send(eventA{}), |
|
|
"expected sending to a stopped routine to fail") |
|
|
"expected sending to a stopped routine to fail") |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -86,7 +86,7 @@ func genStatefulHandler(maxCount int) handleFunc { |
|
|
|
|
|
|
|
|
func feedback(r *Routine) { |
|
|
func feedback(r *Routine) { |
|
|
for event := range r.next() { |
|
|
for event := range r.next() { |
|
|
r.trySend(event) |
|
|
|
|
|
|
|
|
r.send(event) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -100,7 +100,7 @@ func TestStatefulRoutine(t *testing.T) { |
|
|
go feedback(routine) |
|
|
go feedback(routine) |
|
|
<-routine.ready() |
|
|
<-routine.ready() |
|
|
|
|
|
|
|
|
assert.True(t, routine.trySend(eventA{}), |
|
|
|
|
|
|
|
|
assert.True(t, routine.send(eventA{}), |
|
|
"expected sending to a started routine to succeed") |
|
|
"expected sending to a started routine to succeed") |
|
|
|
|
|
|
|
|
final := <-routine.final() |
|
|
final := <-routine.final() |
|
@ -137,7 +137,7 @@ func TestPriority(t *testing.T) { |
|
|
<-routine.ready() |
|
|
<-routine.ready() |
|
|
go func() { |
|
|
go func() { |
|
|
for { |
|
|
for { |
|
|
routine.trySend(lowPriorityEvent{}) |
|
|
|
|
|
|
|
|
routine.send(lowPriorityEvent{}) |
|
|
time.Sleep(1 * time.Millisecond) |
|
|
time.Sleep(1 * time.Millisecond) |
|
|
} |
|
|
} |
|
|
}() |
|
|
}() |
|
@ -145,7 +145,7 @@ func TestPriority(t *testing.T) { |
|
|
|
|
|
|
|
|
assert.True(t, routine.isRunning(), |
|
|
assert.True(t, routine.isRunning(), |
|
|
"expected an started routine") |
|
|
"expected an started routine") |
|
|
assert.True(t, routine.trySend(highPriorityEvent{}), |
|
|
|
|
|
|
|
|
assert.True(t, routine.send(highPriorityEvent{}), |
|
|
"expected send to succeed even when saturated") |
|
|
"expected send to succeed even when saturated") |
|
|
|
|
|
|
|
|
assert.Equal(t, done, <-routine.final()) |
|
|
assert.Equal(t, done, <-routine.final()) |
|
|