Skip to content

Commit

Permalink
Improve Redis container setup and async test handling
Browse files Browse the repository at this point in the history
- Updated `createTestRedis` in `act_helpers_test.go` to use `wait.ForAll` for better reliability by ensuring both log readiness and port listening.
- Enhanced `Test_Run_Async_Redis` in `registry_test.go` by adding a context with a timeout to the consumer subscription for improved test robustness.
- Simplified the sleep duration in `Test_Run_Async_Redis` to reduce unnecessary wait time.
  • Loading branch information
sinadarbouy committed Dec 9, 2024
1 parent 01c2234 commit 5d0c65f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
5 changes: 4 additions & 1 deletion act/act_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ func createTestRedis(t *testing.T) string {
req := testcontainers.ContainerRequest{
Image: "redis:6",
ExposedPorts: []string{"6379/tcp"},
WaitingFor: wait.ForLog("Ready to accept connections"),
WaitingFor: wait.ForAll(
wait.ForLog("Ready to accept connections"),
wait.ForListeningPort("6379/tcp"),
),
}
redisContainer, err := testcontainers.GenericContainer(
ctx, testcontainers.GenericContainerRequest{
Expand Down
12 changes: 7 additions & 5 deletions act/registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -747,10 +747,12 @@ func Test_Run_Async_Redis(t *testing.T) {
consumer, err := sdkAct.NewConsumer(hclogger, rdb, 5, "test-async-chan")
require.NoError(t, err)

require.NoError(t, consumer.Subscribe(context.Background(), func(ctx context.Context, task []byte) error {
err := actRegistry.runAsyncActionFn(ctx, task)
waitGroup.Done()
return err
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()

require.NoError(t, consumer.Subscribe(ctx, func(ctx context.Context, task []byte) error {
defer waitGroup.Done()
return actRegistry.runAsyncActionFn(ctx, task)
}))

outputs := actRegistry.Apply([]sdkAct.Signal{
Expand Down Expand Up @@ -781,7 +783,7 @@ func Test_Run_Async_Redis(t *testing.T) {
assert.Equal(t, err, gerr.ErrAsyncAction, "expected async action sentinel error")
assert.Nil(t, result, "expected nil result")

time.Sleep(time.Millisecond * 2) // wait for async action to complete
time.Sleep(time.Millisecond) // wait for async action to complete

// The following is the expected log output from running the async action.
assert.Contains(t, out.String(), "{\"level\":\"debug\",\"action\":\"log\",\"executionMode\":\"async\",\"message\":\"Running action\"}") //nolint:lll
Expand Down

0 comments on commit 5d0c65f

Please sign in to comment.