(t *testing.T)
| 75 | } |
| 76 | |
| 77 | func TestNewParallelExecutor(t *testing.T) { |
| 78 | assert := assert.New(t) |
| 79 | |
| 80 | ctx := context.Background() |
| 81 | |
| 82 | count := 0 |
| 83 | activeCount := 0 |
| 84 | maxCount := 0 |
| 85 | emptyWorkflow := NewPipelineExecutor(func(_ context.Context) error { |
| 86 | count++ |
| 87 | |
| 88 | activeCount++ |
| 89 | if activeCount > maxCount { |
| 90 | maxCount = activeCount |
| 91 | } |
| 92 | time.Sleep(2 * time.Second) |
| 93 | activeCount-- |
| 94 | |
| 95 | return nil |
| 96 | }) |
| 97 | |
| 98 | err := NewParallelExecutor(2, emptyWorkflow, emptyWorkflow, emptyWorkflow)(ctx) |
| 99 | |
| 100 | assert.Equal(3, count, "should run all 3 executors") |
| 101 | assert.Equal(2, maxCount, "should run at most 2 executors in parallel") |
| 102 | assert.Nil(err) |
| 103 | |
| 104 | // Reset to test running the executor with 0 parallelism |
| 105 | count = 0 |
| 106 | activeCount = 0 |
| 107 | maxCount = 0 |
| 108 | |
| 109 | errSingle := NewParallelExecutor(0, emptyWorkflow, emptyWorkflow, emptyWorkflow)(ctx) |
| 110 | |
| 111 | assert.Equal(3, count, "should run all 3 executors") |
| 112 | assert.Equal(1, maxCount, "should run at most 1 executors in parallel") |
| 113 | assert.Nil(errSingle) |
| 114 | } |
| 115 | |
| 116 | func TestNewParallelExecutorFailed(t *testing.T) { |
| 117 | assert := assert.New(t) |
nothing calls this directly
no test coverage detected
searching dependent graphs…