tickOnce traps the worker's NewTicker call, starts the worker, fires one tick, waits for it to finish by observing the given tickDone channel, then shuts the worker down. The tickDone channel must be closed when the last expected operation in the tick completes. For tests where the tick does nothing
(
ctx context.Context,
t *testing.T,
mClock *quartz.Mock,
worker *gitsync.Worker,
tickDone <-chan struct{},
)
| 112 | // stale rows or store error), tickDone should be closed inside |
| 113 | // acquireStaleChatDiffStatuses. |
| 114 | func tickOnce( |
| 115 | ctx context.Context, |
| 116 | t *testing.T, |
| 117 | mClock *quartz.Mock, |
| 118 | worker *gitsync.Worker, |
| 119 | tickDone <-chan struct{}, |
| 120 | ) { |
| 121 | t.Helper() |
| 122 | |
| 123 | trap := mClock.Trap().NewTicker("gitsync", "worker") |
| 124 | defer trap.Close() |
| 125 | |
| 126 | workerCtx, cancel := context.WithCancel(ctx) |
| 127 | defer cancel() |
| 128 | |
| 129 | go worker.Start(workerCtx) |
| 130 | |
| 131 | // Wait for the worker to create its ticker. |
| 132 | trap.MustWait(ctx).MustRelease(ctx) |
| 133 | |
| 134 | // Fire one tick. The waiter resolves when the channel receive |
| 135 | // completes, not when w.tick() returns, so we use tickDone to |
| 136 | // know when to proceed. |
| 137 | _, w := mClock.AdvanceNext() |
| 138 | w.MustWait(ctx) |
| 139 | |
| 140 | // Wait for the tick's business logic to finish. |
| 141 | select { |
| 142 | case <-tickDone: |
| 143 | case <-ctx.Done(): |
| 144 | t.Fatal("timed out waiting for tick to complete") |
| 145 | } |
| 146 | |
| 147 | cancel() |
| 148 | <-worker.Done() |
| 149 | } |
| 150 | |
| 151 | func TestWorker_SkipsFreshRows(t *testing.T) { |
| 152 | t.Parallel() |
no test coverage detected