Skip to content

Commit

Permalink
fix flaky tests
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-nicolas committed Jan 24, 2024
1 parent b5eeba6 commit 066e443
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions components/payments/cmd/connectors/internal/task/scheduler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ func TestTaskScheduler(t *testing.T) {
descriptor1 := newDescriptor()
descriptor2 := newDescriptor()

task1Launched := make(chan struct{})
task2Launched := make(chan struct{})

task1Terminated := make(chan struct{})
task2Terminated := make(chan struct{})

Expand All @@ -177,6 +180,7 @@ func TestTaskScheduler(t *testing.T) {
switch string(descriptor) {
case string(descriptor1):
return func(ctx context.Context) error {
close(task1Launched)
select {
case <-task1Terminated:
return nil
Expand All @@ -186,6 +190,7 @@ func TestTaskScheduler(t *testing.T) {
}
case string(descriptor2):
return func(ctx context.Context) error {
close(task2Launched)
select {
case <-task2Terminated:
return nil
Expand All @@ -206,13 +211,25 @@ func TestTaskScheduler(t *testing.T) {
ScheduleOption: models.OPTIONS_RUN_NOW,
RestartOption: models.OPTIONS_RESTART_NEVER,
}))
require.Eventually(t, TaskActive(store, connectorID, descriptor1), time.Second, 100*time.Millisecond)
require.Eventually(t, TaskActive(store, connectorID, descriptor2), time.Second, 100*time.Millisecond)
close(task1Terminated)
require.Eventually(t, TaskTerminated(store, connectorID, descriptor1), time.Second, 100*time.Millisecond)
require.Eventually(t, TaskActive(store, connectorID, descriptor2), time.Second, 100*time.Millisecond)
close(task2Terminated)
require.Eventually(t, TaskTerminated(store, connectorID, descriptor2), time.Second, 100*time.Millisecond)

select {
case <-task1Launched:
require.Eventually(t, TaskActive(store, connectorID, descriptor1), time.Second, 100*time.Millisecond)
require.Eventually(t, TaskActive(store, connectorID, descriptor2), time.Second, 100*time.Millisecond)
close(task1Terminated)
require.Eventually(t, TaskTerminated(store, connectorID, descriptor1), time.Second, 100*time.Millisecond)
require.Eventually(t, TaskActive(store, connectorID, descriptor2), time.Second, 100*time.Millisecond)
close(task2Terminated)
require.Eventually(t, TaskTerminated(store, connectorID, descriptor2), time.Second, 100*time.Millisecond)
case <-task2Launched:
require.Eventually(t, TaskActive(store, connectorID, descriptor1), time.Second, 100*time.Millisecond)
require.Eventually(t, TaskActive(store, connectorID, descriptor2), time.Second, 100*time.Millisecond)
close(task2Terminated)
require.Eventually(t, TaskTerminated(store, connectorID, descriptor2), time.Second, 100*time.Millisecond)
require.Eventually(t, TaskActive(store, connectorID, descriptor1), time.Second, 100*time.Millisecond)
close(task1Terminated)
require.Eventually(t, TaskTerminated(store, connectorID, descriptor1), time.Second, 100*time.Millisecond)
}
})

t.Run("Stop scheduler", func(t *testing.T) {
Expand Down

0 comments on commit 066e443

Please sign in to comment.