TestScheduler_ConcurrentStepNotify 测试并发步骤通知
(t *testing.T)
| 406 | |
| 407 | // TestScheduler_ConcurrentStepNotify 测试并发步骤通知 |
| 408 | func TestScheduler_ConcurrentStepNotify(t *testing.T) { |
| 409 | scheduler := NewScheduler(nil) |
| 410 | defer scheduler.Shutdown() |
| 411 | |
| 412 | var callCount int32 |
| 413 | |
| 414 | if _, err := scheduler.EverySteps(1, func(ctx context.Context, stepCount int) error { |
| 415 | atomic.AddInt32(&callCount, 1) |
| 416 | return nil |
| 417 | }); err != nil { |
| 418 | t.Fatalf("Failed to create step task: %v", err) |
| 419 | } |
| 420 | |
| 421 | // 顺序通知 (避免 LastTriggered 的竞态问题) |
| 422 | // 并发通知会导致某些步骤被跳过 |
| 423 | for i := 1; i <= 10; i++ { |
| 424 | scheduler.NotifyStep(i) |
| 425 | } |
| 426 | |
| 427 | time.Sleep(200 * time.Millisecond) |
| 428 | |
| 429 | // 验证所有步骤都被处理 |
| 430 | count := atomic.LoadInt32(&callCount) |
| 431 | if count != 10 { |
| 432 | t.Errorf("Expected 10 calls, got %d", count) |
| 433 | } |
| 434 | } |
nothing calls this directly
no test coverage detected