|
|
|
|
@ -1,6 +1,7 @@
|
|
|
|
|
package multistep
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"reflect"
|
|
|
|
|
"testing"
|
|
|
|
|
"time"
|
|
|
|
|
@ -20,7 +21,7 @@ func TestBasicRunner_Run(t *testing.T) {
|
|
|
|
|
stepB := &TestStepAcc{Data: "b"}
|
|
|
|
|
|
|
|
|
|
r := &BasicRunner{Steps: []Step{stepA, stepB}}
|
|
|
|
|
r.Run(data)
|
|
|
|
|
r.Run(context.Background(), data)
|
|
|
|
|
|
|
|
|
|
// Test run data
|
|
|
|
|
expected := []string{"a", "b"}
|
|
|
|
|
@ -53,7 +54,7 @@ func TestBasicRunner_Run_Halt(t *testing.T) {
|
|
|
|
|
stepC := &TestStepAcc{Data: "c"}
|
|
|
|
|
|
|
|
|
|
r := &BasicRunner{Steps: []Step{stepA, stepB, stepC}}
|
|
|
|
|
r.Run(data)
|
|
|
|
|
r.Run(context.Background(), data)
|
|
|
|
|
|
|
|
|
|
// Test run data
|
|
|
|
|
expected := []string{"a", "b"}
|
|
|
|
|
@ -86,12 +87,12 @@ func TestBasicRunner_Run_Run(t *testing.T) {
|
|
|
|
|
stepWait := &TestStepWaitForever{}
|
|
|
|
|
r := &BasicRunner{Steps: []Step{stepInt, stepWait}}
|
|
|
|
|
|
|
|
|
|
go r.Run(new(BasicStateBag))
|
|
|
|
|
go r.Run(context.Background(), new(BasicStateBag))
|
|
|
|
|
// wait until really running
|
|
|
|
|
<-ch
|
|
|
|
|
|
|
|
|
|
// now try to run aain
|
|
|
|
|
r.Run(new(BasicStateBag))
|
|
|
|
|
r.Run(context.Background(), new(BasicStateBag))
|
|
|
|
|
|
|
|
|
|
// should not get here in nominal codepath
|
|
|
|
|
t.Errorf("Was able to run an already running BasicRunner")
|
|
|
|
|
@ -107,10 +108,9 @@ func TestBasicRunner_Cancel(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
r := &BasicRunner{Steps: []Step{stepA, stepB, stepInt, stepC}}
|
|
|
|
|
|
|
|
|
|
// cancelling an idle Runner is a no-op
|
|
|
|
|
r.Cancel()
|
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
|
|
|
|
|
|
go r.Run(data)
|
|
|
|
|
go r.Run(ctx, data)
|
|
|
|
|
|
|
|
|
|
// Wait until we reach the sync point
|
|
|
|
|
responseCh := <-ch
|
|
|
|
|
@ -118,7 +118,7 @@ func TestBasicRunner_Cancel(t *testing.T) {
|
|
|
|
|
// Cancel then continue chain
|
|
|
|
|
cancelCh := make(chan bool)
|
|
|
|
|
go func() {
|
|
|
|
|
r.Cancel()
|
|
|
|
|
cancel()
|
|
|
|
|
cancelCh <- true
|
|
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
@ -161,7 +161,7 @@ func TestBasicRunner_Cancel_Special(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
state := new(BasicStateBag)
|
|
|
|
|
state.Put("runner", r)
|
|
|
|
|
r.Run(state)
|
|
|
|
|
r.Run(context.Background(), state)
|
|
|
|
|
|
|
|
|
|
// test that state contains cancelled
|
|
|
|
|
if _, ok := state.GetOk(StateCancelled); !ok {
|
|
|
|
|
|