MCPcopy Index your code
hub / github.com/coder/coder / tickOnce

Function tickOnce

coderd/x/gitsync/worker_test.go:114–149  ·  view source on GitHub ↗

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{},
)

Source from the content-addressed store, hash-verified

112// stale rows or store error), tickDone should be closed inside
113// acquireStaleChatDiffStatuses.
114func 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
151func TestWorker_SkipsFreshRows(t *testing.T) {
152 t.Parallel()

Calls 5

FatalMethod · 0.80
HelperMethod · 0.65
CloseMethod · 0.65
StartMethod · 0.65
DoneMethod · 0.45

Tested by

no test coverage detected