test(core): build the swipe rig's timer mock before core runs
- commit
- 3e41022427a3ff31e8314678815acae932da9ffc
- author
- brice · · 2026-10-04 16:03 UTC
- committer
- brice · · 2026-10-04 19:08 UTC
- parent
- f2967d7
- signature
- GPG Verified
CD88F9E564E0102646FB6077A1A07C7C7C3E349D· arch-gpg Verified for the committer email
1 file · +7 -7
M internal/core/swipe_test.go +7 -7
| @@ -46,13 +46,13 @@ func startSwipe(t *testing.T, edit func(*ports.Config)) *swipeRig { | |||
| 46 | 46 | defer r.mu.Unlock() | |
| 47 | 47 | return r.now | |
| 48 | 48 | }).Maybe() | |
| 49 | - | // The fallback timer never fires: frames come from the test. | |
| 50 | - | clock.EXPECT().NewTimer(mock.Anything).RunAndReturn(func(time.Duration) ports.Timer { | |
| 51 | - | timer := portsmocks.NewMockTimer(t) | |
| 52 | - | timer.EXPECT().C().Return(make(chan time.Time)).Maybe() | |
| 53 | - | timer.EXPECT().Stop().Return(true).Maybe() | |
| 54 | - | return timer | |
| 55 | - | }).Maybe() | |
| 49 | + | // The fallback timer never fires: frames come from the test. One timer | |
| 50 | + | // built before core runs: a mock created by core while the test ends | |
| 51 | + | // would race its own cleanup check. | |
| 52 | + | timer := portsmocks.NewMockTimer(t) | |
| 53 | + | timer.EXPECT().C().Return(make(chan time.Time)).Maybe() | |
| 54 | + | timer.EXPECT().Stop().Return(true).Maybe() | |
| 55 | + | clock.EXPECT().NewTimer(mock.Anything).Return(timer).Maybe() | |
| 56 | 56 | c, err := core.New(cfg, core.Channels{Client: r.client, Input: r.input, Output: r.output, Config: r.reload, Commands: r.commands, Scenes: r.scenes, Spawn: r.spawn, State: r.state, Clock: clock, Frames: r.frames}) | |
| 57 | 57 | if err != nil { | |
| 58 | 58 | t.Fatal(err) | |
| @@ -46,13 +46,13 @@ func startSwipe(t *testing.T, edit func(*ports.Config)) *swipeRig { | |||||
| 46 | defer r.mu.Unlock() | 46 | defer r.mu.Unlock() | ||
| 47 | return r.now | 47 | return r.now | ||
| 48 | }).Maybe() | 48 | }).Maybe() | ||
| 49 | - | // The fallback timer never fires: frames come from the test. | 49 | + | // The fallback timer never fires: frames come from the test. One timer |
| 50 | - | clock.EXPECT().NewTimer(mock.Anything).RunAndReturn(func(time.Duration) ports.Timer { | 50 | + | // built before core runs: a mock created by core while the test ends |
| 51 | - | timer := portsmocks.NewMockTimer(t) | 51 | + | // would race its own cleanup check. |
| 52 | - | timer.EXPECT().C().Return(make(chan time.Time)).Maybe() | 52 | + | timer := portsmocks.NewMockTimer(t) |
| 53 | - | timer.EXPECT().Stop().Return(true).Maybe() | 53 | + | timer.EXPECT().C().Return(make(chan time.Time)).Maybe() |
| 54 | - | return timer | 54 | + | timer.EXPECT().Stop().Return(true).Maybe() |
| 55 | - | }).Maybe() | 55 | + | clock.EXPECT().NewTimer(mock.Anything).Return(timer).Maybe() |
| 56 | c, err := core.New(cfg, core.Channels{Client: r.client, Input: r.input, Output: r.output, Config: r.reload, Commands: r.commands, Scenes: r.scenes, Spawn: r.spawn, State: r.state, Clock: clock, Frames: r.frames}) | 56 | c, err := core.New(cfg, core.Channels{Client: r.client, Input: r.input, Output: r.output, Config: r.reload, Commands: r.commands, Scenes: r.scenes, Spawn: r.spawn, State: r.state, Clock: clock, Frames: r.frames}) | ||
| 57 | if err != nil { | 57 | if err != nil { | ||
| 58 | t.Fatal(err) | 58 | t.Fatal(err) | ||