Skip to content

Commit 342c383

Browse files
authored
Merged the timeout logic for the tests in internal_workers_test.go (#1225)
* Merged the timeout loging for the tests in internal_workers_test.go * Fixed the import order and fixed the name of the function
1 parent 5454503 commit 342c383

File tree

1 file changed

+20
-27
lines changed

1 file changed

+20
-27
lines changed

internal/internal_workers_test.go

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -346,14 +346,7 @@ func (s *WorkersTestSuite) TestLongRunningDecisionTask() {
346346
)
347347
worker.RegisterActivity(localActivitySleep)
348348

349-
worker.Start()
350-
// wait for test to complete
351-
select {
352-
case <-doneCh:
353-
break
354-
case <-time.After(time.Second * 4):
355-
}
356-
worker.Stop()
349+
startWorkerAndWait(s, worker, &doneCh)
357350

358351
s.True(isWorkflowCompleted)
359352
s.Equal(2, localActivityCalledCount)
@@ -531,9 +524,7 @@ func (s *WorkersTestSuite) TestQueryTask_WorkflowCacheEvicted() {
531524
RegisterActivityOptions{Name: activityType},
532525
)
533526

534-
worker.Start()
535-
<-doneCh
536-
worker.Stop()
527+
startWorkerAndWait(s, worker, &doneCh)
537528
}
538529

539530
func (s *WorkersTestSuite) TestMultipleLocalActivities() {
@@ -653,14 +644,7 @@ func (s *WorkersTestSuite) TestMultipleLocalActivities() {
653644
)
654645
worker.RegisterActivity(localActivitySleep)
655646

656-
worker.Start()
657-
// wait for test to complete
658-
select {
659-
case <-doneCh:
660-
break
661-
case <-time.After(time.Second * 5):
662-
}
663-
worker.Stop()
647+
startWorkerAndWait(s, worker, &doneCh)
664648

665649
s.True(isWorkflowCompleted)
666650
s.Equal(2, localActivityCalledCount)
@@ -770,14 +754,7 @@ func (s *WorkersTestSuite) TestLocallyDispatchedActivity() {
770754
)
771755
worker.RegisterActivityWithOptions(activitySleep, RegisterActivityOptions{Name: "activitySleep"})
772756

773-
worker.Start()
774-
// wait for test to complete
775-
select {
776-
case <-doneCh:
777-
break
778-
case <-time.After(1 * time.Second):
779-
}
780-
worker.Stop()
757+
startWorkerAndWait(s, worker, &doneCh)
781758

782759
s.True(isActivityResponseCompleted)
783760
s.Equal(1, activityCalledCount)
@@ -888,6 +865,8 @@ func (s *WorkersTestSuite) TestMultipleLocallyDispatchedActivity() {
888865
worker.Start()
889866

890867
// wait for test to complete
868+
// This test currently never completes, however after the timeout the asserts are true
869+
// so the test passes, I believe this is an error.
891870
select {
892871
case <-doneCh:
893872
break
@@ -899,3 +878,17 @@ func (s *WorkersTestSuite) TestMultipleLocallyDispatchedActivity() {
899878
s.True(activityResponseCompletedCount > 0)
900879
s.True(activityCalledCount > 0)
901880
}
881+
882+
// wait for test to complete - timeout and fail after 10 seconds to not block execution of other tests
883+
func startWorkerAndWait(s *WorkersTestSuite, worker *aggregatedWorker, doneCh *chan struct{}) {
884+
s.T().Helper()
885+
worker.Start()
886+
// wait for test to complete
887+
select {
888+
case <-*doneCh:
889+
return
890+
case <-time.After(10 * time.Second):
891+
s.Fail("Test timed out")
892+
}
893+
worker.Stop()
894+
}

0 commit comments

Comments
 (0)