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)
| 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. |
| 168 | func 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 |
| 212 | func TestAcquirer_DifferentDomains(t *testing.T) { |
nothing calls this directly
no test coverage detected