MCPcopy Index your code
hub / github.com/codnect/chrono / TestSimpleTaskExecutor_Schedule_MultiTasks

Function TestSimpleTaskExecutor_Schedule_MultiTasks

executor_test.go:174–215  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

172}
173
174func TestSimpleTaskExecutor_Schedule_MultiTasks(t *testing.T) {
175 executor := NewSimpleTaskExecutor(NewDefaultTaskRunner())
176
177 var task1Counter int32
178 var task2Counter int32
179 var task3Counter int32
180
181 task1, err := executor.ScheduleAtFixedRate(func(ctx context.Context) {
182 atomic.AddInt32(&task1Counter, 1)
183 <-time.After(500 * time.Millisecond)
184 }, 1*time.Second, 200*time.Millisecond)
185
186 assert.Nil(t, err)
187
188 task2, err := executor.ScheduleWithFixedDelay(func(ctx context.Context) {
189 atomic.AddInt32(&task2Counter, 1)
190 <-time.After(500 * time.Millisecond)
191 }, 0, 200*time.Millisecond)
192
193 assert.Nil(t, err)
194
195 task3, err := executor.ScheduleAtFixedRate(func(ctx context.Context) {
196 atomic.AddInt32(&task3Counter, 1)
197 }, 0, 200*time.Millisecond)
198
199 assert.Nil(t, err)
200
201 <-time.After(2*time.Second - 50*time.Millisecond)
202
203 task1.Cancel()
204 task2.Cancel()
205 task3.Cancel()
206
207 assert.True(t, task1Counter >= 5 && task1Counter <= 10,
208 "number of scheduled task 1 execution must be between 5 and 10, actual: %d", task1Counter)
209
210 assert.True(t, task2Counter >= 1 && task2Counter <= 3,
211 "number of scheduled task 2 execution must be between 1 and 3, actual: %d", task2Counter)
212
213 assert.True(t, task3Counter >= 1 && task3Counter <= 10,
214 "number of scheduled task execution must be between 5 and 10, actual: %d", task3Counter)
215}
216
217func TestSimpleTaskExecutor_ScheduleWithNilTask(t *testing.T) {
218 executor := NewSimpleTaskExecutor(NewDefaultTaskRunner())

Callers

nothing calls this directly

Calls 5

ScheduleAtFixedRateMethod · 0.95
NewSimpleTaskExecutorFunction · 0.85
NewDefaultTaskRunnerFunction · 0.85
CancelMethod · 0.65

Tested by

no test coverage detected