Skip to content

Commit 2993285

Browse files
authored
test: add SendToChannel helper and replace bare channel sends in functional tests (#9876)
## What changed? Added a `SendToChannel(ctx, ch)` helper to `FunctionalTestBase`, mirroring the existing `WaitForChannel`, and replaced all bare `ch <- struct{}{}` sends in functional test bodies with calls to it. ## Why? Bare channel sends in test bodies silently hang when the receiving goroutine has stalled or died, causing tests to block until the overall test timeout rather than failing fast with a useful message. `WaitForChannel` already existed to solve this for receives, `SendToChannel` closes the gap for sends. ## How did you test it? - [ ] built - [ ] run locally and tested manually - [ ] covered by existing tests - [ ] added new unit test(s) - [ ] added new functional test(s) ## Potential risks None, this is a pure test-helper addition.
1 parent ad37da9 commit 2993285

5 files changed

Lines changed: 23 additions & 14 deletions

File tree

tests/activity_api_pause_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ func (s *ActivityAPIPauseClientTestSuite) TestActivityPauseApi_WhileRunning() {
115115
}, 5*time.Second, 500*time.Millisecond)
116116

117117
// unblock the activity
118-
activityPausedCn <- struct{}{}
118+
env.SendToChannel(ctx, activityPausedCn)
119119
// make sure activity is paused on server and completed on the worker
120120
s.EventuallyWithT(func(t *assert.CollectT) {
121121
description, err := env.SdkClient().DescribeWorkflowExecution(ctx, workflowRun.GetID(), workflowRun.GetRunID())
@@ -264,7 +264,7 @@ func (s *ActivityAPIPauseClientTestSuite) TestActivityPauseApi_IncreaseAttemptsO
264264
}, 5*time.Second, 500*time.Millisecond)
265265

266266
// End the activity
267-
activityPausedCn <- struct{}{}
267+
env.SendToChannel(ctx, activityPausedCn)
268268

269269
s.EventuallyWithT(func(t *assert.CollectT) {
270270
description, err := env.SdkClient().DescribeWorkflowExecution(ctx, workflowRun.GetID(), workflowRun.GetRunID())
@@ -632,7 +632,7 @@ func (s *ActivityAPIPauseClientTestSuite) TestActivityPauseApi_WithReset() {
632632
}, 5*time.Second, 100*time.Millisecond)
633633

634634
// let activity finish
635-
activityCompleteCn <- struct{}{}
635+
env.SendToChannel(ctx, activityCompleteCn)
636636

637637
// wait for workflow to finish
638638
var out string

tests/nexus_workflow_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1765,7 +1765,7 @@ func (s *NexusWorkflowTestSuite) TestNexusOperationCancelBeforeStarted_Cancelati
17651765
})
17661766
s.NoError(err)
17671767

1768-
canStartCh <- struct{}{}
1768+
env.SendToChannel(ctx, canStartCh)
17691769
env.WaitForChannel(ctx, cancelSentCh)
17701770

17711771
// Terminate the workflow for good measure.

tests/pause_workflow_execution_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ func (s *PauseWorkflowExecutionSuite) TestPauseUnpauseWorkflowExecution() {
233233
}, 5*time.Second, 200*time.Millisecond)
234234

235235
// Unblock the activity to complete the workflow.
236-
s.activityCompletedCh <- struct{}{}
236+
s.SendToChannel(ctx, s.activityCompletedCh)
237237

238238
// assert that the workflow completes now.
239239
s.EventuallyWithT(func(t *assert.CollectT) {
@@ -591,7 +591,7 @@ func (s *PauseWorkflowExecutionSuite) TestQueryWorkflowWhenPaused() {
591591
s.NotNil(unpauseResp)
592592

593593
// Unblock the activity and send the signal to complete the workflow.
594-
s.activityCompletedCh <- struct{}{}
594+
s.SendToChannel(ctx, s.activityCompletedCh)
595595
err = s.SdkClient().SignalWorkflow(ctx, workflowID, runID, s.testEndSignal, "test end signal")
596596
s.NoError(err)
597597

@@ -818,7 +818,7 @@ func (s *PauseWorkflowExecutionSuite) TestPauseWorkflowExecutionAlreadyPaused()
818818
}, 5*time.Second, 200*time.Millisecond)
819819

820820
// Unblock the activity and send the signal to complete the workflow.
821-
s.activityCompletedCh <- struct{}{}
821+
s.SendToChannel(ctx, s.activityCompletedCh)
822822
err = s.SdkClient().SignalWorkflow(ctx, workflowID, runID, s.testEndSignal, "test end signal")
823823
s.NoError(err)
824824

tests/testcore/functional_test_base.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,15 @@ func (s *FunctionalTestBase) WaitForChannel(ctx context.Context, ch chan struct{
659659
}
660660
}
661661

662+
func (s *FunctionalTestBase) SendToChannel(ctx context.Context, ch chan struct{}) {
663+
s.T().Helper()
664+
select {
665+
case ch <- struct{}{}:
666+
case <-ctx.Done():
667+
s.FailNow("context timeout while sending to channel")
668+
}
669+
}
670+
662671
// TODO (alex): change to nsName namespace.Name
663672
func (s *FunctionalTestBase) SendSignal(nsName string, execution *commonpb.WorkflowExecution, signalName string,
664673
input *commonpb.Payloads, identity string) error {

tests/versioning_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2070,34 +2070,34 @@ func (s *VersioningIntegSuite) TestDispatchActivityUpgrade() {
20702070
s.WaitForChannel(ctx, startedWf)
20712071
rule2 := s.addRedirectRule(ctx, tq, v1, v11)
20722072
s.waitForRedirectRulePropagation(ctx, tq, rule2)
2073-
proceedWf <- struct{}{}
2073+
s.SendToChannel(ctx, proceedWf)
20742074

20752075
s.WaitForChannel(ctx, started11)
20762076
// wf assigned build ID should be updated by activity redirect
20772077
s.validateWorkflowBuildIds(ctx, run.GetID(), run.GetRunID(), v11, true, v1, "", []string{v1})
20782078
// let activity finish
2079-
proceed11 <- struct{}{}
2079+
s.SendToChannel(ctx, proceed11)
20802080

20812081
// wf replays on 1.1 so need to unblock it an extra time
20822082
s.WaitForChannel(ctx, startedWf)
2083-
proceedWf <- struct{}{}
2083+
s.SendToChannel(ctx, proceedWf)
20842084

20852085
s.WaitForChannel(ctx, startedWf)
20862086
rule2 = s.addRedirectRule(ctx, tq, v11, v12)
20872087
s.waitForRedirectRulePropagation(ctx, tq, rule2)
2088-
proceedWf <- struct{}{}
2088+
s.SendToChannel(ctx, proceedWf)
20892089

20902090
s.WaitForChannel(ctx, started12)
20912091
// wf assigned build ID should not be updated by independent activity redirect
20922092
s.validateWorkflowBuildIds(ctx, run.GetID(), run.GetRunID(), v11, true, v11, "", []string{v1})
20932093
// let activity finish
2094-
proceed12 <- struct{}{}
2094+
s.SendToChannel(ctx, proceed12)
20952095

20962096
// wf replays on 1.2 so need to unblock it two extra times
20972097
s.WaitForChannel(ctx, startedWf)
2098-
proceedWf <- struct{}{}
2098+
s.SendToChannel(ctx, proceedWf)
20992099
s.WaitForChannel(ctx, startedWf)
2100-
proceedWf <- struct{}{}
2100+
s.SendToChannel(ctx, proceedWf)
21012101

21022102
var out string
21032103
s.NoError(run.Get(ctx, &out))

0 commit comments

Comments
 (0)