Refine Timezone Deduplication Test for Manager

- Enhanced the test for the Manager's timezone deduplication functionality to ensure the times robot does not trigger multiple times within the same minute on the same day.
- Added detailed assertions to clarify expected behavior and improve test accuracy, particularly regarding the interaction between the times, daemon, and interval robots.
- Updated comments to provide better context and understanding of the test logic and expected outcomes.
This commit is contained in:
Max 2026-01-15 10:07:08 +08:00
parent 4a36090d8f
commit addda7f455

View file

@ -373,6 +373,8 @@ func TestManagerTimezoneDedup(t *testing.T) {
defer cleanupTestRobots(t)
t.Run("times mode - same minute same day should not trigger twice", func(t *testing.T) {
// Create a dedicated manager with only the times robot to isolate the test
// We need to test that times mode dedup works correctly
m := manager.New()
err := m.Start()
assert.NoError(t, err)
@ -387,24 +389,33 @@ func TestManagerTimezoneDedup(t *testing.T) {
ctx := types.NewContext(context.Background(), nil)
// First tick - should trigger
// First tick - should trigger times robot (and daemon/interval)
err = m.Tick(ctx, now)
assert.NoError(t, err)
time.Sleep(200 * time.Millisecond)
firstCount := m.Executor().ExecCount()
assert.GreaterOrEqual(t, firstCount, 1, "First tick should trigger")
// Second tick at 09:00:30 (same minute) - should NOT trigger again
// Second tick at 09:00:30 (same minute) - times robot should NOT trigger again
// But daemon robot will trigger again (it triggers whenever idle)
// And interval robot may trigger again if interval passed
now2 := time.Date(2025, 1, 15, 9, 0, 30, 0, loc)
err = m.Tick(ctx, now2)
assert.NoError(t, err)
time.Sleep(200 * time.Millisecond)
// Count should remain the same (times robot should not trigger twice)
// Note: daemon/interval robots may still trigger, so we check the delta
secondCount := m.Executor().ExecCount()
// The times robot should not have triggered again in the same minute
t.Logf("First count: %d, Second count: %d", firstCount, secondCount)
// The key assertion: times robot triggers once per minute
// First tick: times(1) + daemon(1) + interval(1) = 3
// Second tick: daemon(1) + possibly interval = 1-2 more
// So total should be 4-5, NOT 6 (which would mean times triggered twice)
//
// More precise: the delta between second and first should be <= 2
// (daemon always triggers when idle, interval might trigger)
delta := secondCount - firstCount
assert.LessOrEqual(t, delta, 2, "Times robot should not trigger twice in same minute (delta: %d)", delta)
})
t.Run("times mode - different day should trigger again", func(t *testing.T) {