testutil

package
v0.0.0-...-cf623d3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 8, 2023 License: MIT Imports: 2 Imported by: 0

README

TODO(cretz): Test suite utilities including a delayed callback wrapper w/ sleeping inline

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddSequence

func AddSequence(env *testsuite.TestWorkflowEnvironment, fn func(seq Sequencer))

AddSequence invokes RegisterDelayedCallback that will start the given function and continually register new callbacks as sleeps are needed.

Example
var suite testsuite.WorkflowTestSuite
suite.SetLogger(simpleLogger)
env := suite.NewTestWorkflowEnvironment()

// Add sequence of stuff
testutil.AddSequence(env, func(seq testutil.Sequencer) {
	fmt.Println("Started")
	env.SignalWorkflow("signal", "signal1")
	env.SignalWorkflow("signal", "signal2")
	seq.Tick()
	env.SignalWorkflow("signal", "signal3")
	env.SignalWorkflow("signal", "signal4")
	seq.Sleep(10 * time.Hour)
	env.SignalWorkflow("signal", "signal5")
	env.SignalWorkflow("signal", "signal6")
	seq.Sleep(0)
	env.SignalWorkflow("signal", "finish")
	fmt.Println("Finished")
})

// Run workflow that captures signals
env.ExecuteWorkflow(func(ctx workflow.Context) (signalsReceived []string, err error) {
	sig := workflow.GetSignalChannel(ctx, "signal")
	var sigVal string
	for sigVal != "finish" {
		sig.Receive(ctx, &sigVal)
		signalsReceived = append(signalsReceived, sigVal)
	}
	return
})

// Dump signals received
if env.GetWorkflowError() != nil {
	panic(env.GetWorkflowError())
}
var signalsReceived []string
env.GetWorkflowResult(&signalsReceived)
fmt.Println("Signals Received: " + strings.Join(signalsReceived, ", "))
Output:

Started
DEBUG Auto fire timer TimerID 1 TimerDuration 1ns TimeSkipped 1ns
DEBUG Auto fire timer TimerID 2 TimerDuration 10h0m0s TimeSkipped 10h0m0s
Finished
Signals Received: signal1, signal2, signal3, signal4, signal5, signal6, finish

Types

type Sequencer

type Sequencer interface {
	// Tick yields to workflow. This is just Sleep(1) here as a convenience.
	Tick()

	// Sleep skips the given duration before executing the next code
	Sleep(time.Duration)
}

Sequencer allows you to wait during sequences

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL