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

Function TestAcquirer_RetriesPending

coderd/provisionerdserver/acquirer_test.go:168–209  ·  view source on GitHub ↗

TestAcquirer_RetriesPending tests that if we get a job posting while a db call is in progress we retry to acquire a job immediately, even if the first call returned no jobs. We want this behavior since the query that found no jobs could have resolved before the job was posted, but the query result

(t *testing.T)

Source from the content-addressed store, hash-verified

166// behavior since the query that found no jobs could have resolved before the job was posted, but
167// the query result could reach us later than the posting over the pubsub.
168func TestAcquirer_RetriesPending(t *testing.T) {
169 t.Parallel()
170 fs := newFakeOrderedStore()
171 ps := pubsub.NewInMemory()
172 ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitShort)
173 defer cancel()
174 logger := testutil.Logger(t)
175 uut := provisionerdserver.NewAcquirer(ctx, logger.Named("acquirer"), fs, ps)
176
177 orgID := uuid.New()
178 workerID := uuid.New()
179 pt := []database.ProvisionerType{database.ProvisionerTypeEcho}
180 tags := provisionerdserver.Tags{
181 "environment": "on-prem",
182 }
183 acquiree := newTestAcquiree(t, orgID, workerID, pt, tags)
184 jobID := uuid.New()
185
186 acquiree.startAcquire(ctx, uut)
187 require.Eventually(t, func() bool {
188 fs.mu.Lock()
189 defer fs.mu.Unlock()
190 return len(fs.params) == 1
191 }, testutil.WaitShort, testutil.IntervalFast)
192
193 // First call to DB is in progress. Send in posting
194 postJob(t, ps, database.ProvisionerTypeEcho, provisionerdserver.Tags{})
195 // there is a race between the posting being processed and the DB call
196 // returning. In either case we should retry, but we're trying to hit the
197 // case where the posting is processed first, so sleep a little bit to give
198 // it a chance.
199 time.Sleep(testutil.IntervalMedium)
200
201 // Now, when first DB call returns ErrNoRows we retry.
202 err := fs.sendCtx(ctx, database.ProvisionerJob{}, sql.ErrNoRows)
203 require.NoError(t, err)
204 err = fs.sendCtx(ctx, database.ProvisionerJob{ID: jobID}, nil)
205 require.NoError(t, err)
206
207 job := acquiree.success(ctx)
208 require.Equal(t, jobID, job.ID)
209}
210
211// TestAcquirer_DifferentDomains tests that acquirees with different tags don't block each other
212func TestAcquirer_DifferentDomains(t *testing.T) {

Callers

nothing calls this directly

Calls 14

NewInMemoryFunction · 0.92
LoggerFunction · 0.92
NewAcquirerFunction · 0.92
newFakeOrderedStoreFunction · 0.85
newTestAcquireeFunction · 0.85
postJobFunction · 0.85
NamedMethod · 0.80
startAcquireMethod · 0.80
sendCtxMethod · 0.80
successMethod · 0.80
NewMethod · 0.65
LockMethod · 0.45

Tested by

no test coverage detected