Hi wrote a simple workflow to simulate my real workflow that is either waits for a signal or times out by timer.
I would appreciate a test example on how to test this code, the examples you have always rely on timer code (samples-go: mutex).
Also if possible please publish a link to documentation on how to do Integration Tests with Temporal.
func (s *fakeSuite) TestSignalFirst() {
s.env.ExecuteWorkflow(Workflow)
s.env.SignalWorkflow("signal-name", "signal-value")
s.NoError(s.env.GetWorkflowError())
s.True(s.env.IsWorkflowCompleted())
var result string
s.env.GetWorkflowResult(&result)
s.Equal("signal-value", result )
}
The code that should act on Signal is not run since the Timer is fired immediately after I ExecuteWorkflow and I receive a timeout message
Send signal from the delayed callback registered through RegisterDelayedCallback. I’m pretty sure it works. If you cannot make it work give us a reproduction of the issue.
Regarding integration testing, it really depends. For example, if you are referring to testing activities which talks to say HTTP APIs, you can use https://github.com/dnaeon/go-vcr or similar for capturing data from real backends. Alternatively, you can use Go’s built-in httptest.NewServer.
Thank you for your replies, just to make sure we all on same page here:
I want to test the code that acts on Signal Receive first - before the timer fires.
Here is the complete example
Here you can find what I tried/did
This one panic since the Workflow isn’t complete
func (s *fakeSuite) TestSignalFirst() {
s.env.RegisterDelayedCallback(func() {}, time.Minute)
s.env.SignalWorkflow("signal-name", "signal-value")
s.NoError(s.env.GetWorkflowError())
s.True(s.env.IsWorkflowCompleted())
var result string
s.env.GetWorkflowResult(&result)
s.Equal("signal-value", result )
}
Output:
fake_test.go:36:
Error Trace: fake_test.go:36
Error: Should be true
Test: TestFake/TestSignalFirst
suite.go:63: test panicked: workflow is not completed
Another failing example, fails on timer instead of waiting.
func (s *fakeSuite) TestSignalFirst() {
s.env.RegisterDelayedCallback(func() {}, time.Minute)
//s.env.SignalWorkflow("signal-name", "signal-value")
s.env.ExecuteWorkflow(Workflow)
s.NoError(s.env.GetWorkflowError())
s.True(s.env.IsWorkflowCompleted())
var result string
s.env.GetWorkflowResult(&result)
s.Equal("signal-value", result )
}
Note that the TestWorkflowEnvironment performs automatic time skipping when a workflow is waiting. So no need to specify so short timeouts. You could specify hour delay and two-hour sleep and the unit test still would execute in milliseconds.