Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9ddad0b

Browse files
committed
fix: only break pubsub after dbgen setup
Signed-off-by: Danny Kopping <[email protected]>
1 parent 42cc3f5 commit 9ddad0b

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

coderd/database/dbgen/dbgen.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -643,8 +643,8 @@ func ProvisionerJob(t testing.TB, db database.Store, ps pubsub.Pubsub, orig data
643643
})
644644
require.NoError(t, err, "insert job")
645645
if ps != nil {
646-
// Advisory, but not essential since acquirer has a background poller to pick up missed jobs.
647-
_ = provisionerjobs.PostJob(ps, job)
646+
err = provisionerjobs.PostJob(ps, job)
647+
require.NoError(t, err, "post job to pubsub")
648648
}
649649
if !orig.StartedAt.Time.IsZero() {
650650
job, err = db.AcquireProvisionerJob(genCtx, database.AcquireProvisionerJobParams{

enterprise/coderd/prebuilds/reconcile_test.go

+11-8
Original file line numberDiff line numberDiff line change
@@ -322,11 +322,6 @@ func TestPrebuildReconciliation(t *testing.T) {
322322
t, &slogtest.Options{IgnoreErrors: true},
323323
).Leveled(slog.LevelDebug)
324324
db, pubSub := dbtestutil.NewDB(t)
325-
if useBrokenPubsub {
326-
pubSub = &brokenPublisher{Pubsub: pubSub}
327-
}
328-
329-
controller := prebuilds.NewStoreReconciler(db, pubSub, cfg, logger, quartz.NewMock(t), prometheus.NewRegistry())
330325

331326
ownerID := uuid.New()
332327
dbgen.User(t, db, database.User{
@@ -369,6 +364,11 @@ func TestPrebuildReconciliation(t *testing.T) {
369364
setupTestDBTemplateVersion(ctx, t, clock, db, pubSub, org.ID, ownerID, template.ID)
370365
}
371366

367+
if useBrokenPubsub {
368+
pubSub = &brokenPublisher{Pubsub: pubSub}
369+
}
370+
controller := prebuilds.NewStoreReconciler(db, pubSub, cfg, logger, quartz.NewMock(t), prometheus.NewRegistry())
371+
372372
// Run the reconciliation multiple times to ensure idempotency
373373
// 8 was arbitrary, but large enough to reasonably trust the result
374374
for i := 1; i <= 8; i++ {
@@ -417,10 +417,13 @@ type brokenPublisher struct {
417417
pubsub.Pubsub
418418
}
419419

420+
// Publish deliberately fails.
421+
// I'm explicitly _not_ checking for EventJobPosted (coderd/database/provisionerjobs/provisionerjobs.go) since that
422+
// requires too much knowledge of the underlying implementation.
420423
func (*brokenPublisher) Publish(event string, _ []byte) error {
421-
// I'm explicitly _not_ checking for EventJobPosted (coderd/database/provisionerjobs/provisionerjobs.go) since that
422-
// requires too much knowledge of the underlying implementation.
423-
return xerrors.Errorf("refusing to publish %q", event)
424+
// Mimick some work being done.
425+
<-time.After(testutil.IntervalFast)
426+
return xerrors.Errorf("failed to publish %q", event)
424427
}
425428

426429
func TestMultiplePresetsPerTemplateVersion(t *testing.T) {

0 commit comments

Comments
 (0)