MCPcopy Create free account
hub / github.com/astercloud/aster / TestScheduler_ConcurrentStepNotify

Function TestScheduler_ConcurrentStepNotify

pkg/core/scheduler_test.go:408–434  ·  view source on GitHub ↗

TestScheduler_ConcurrentStepNotify 测试并发步骤通知

(t *testing.T)

Source from the content-addressed store, hash-verified

406
407// TestScheduler_ConcurrentStepNotify 测试并发步骤通知
408func 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}

Callers

nothing calls this directly

Calls 4

ShutdownMethod · 0.95
EveryStepsMethod · 0.95
NotifyStepMethod · 0.95
NewSchedulerFunction · 0.85

Tested by

no test coverage detected