Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions packages/backend/src/services/errors/ErrorsService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1622,6 +1622,48 @@ describe("ErrorsService.runTick", () => {
)
})

it.effect("a window with more fingerprints than one statement can bind still commits", () => {
// Postgres caps a statement at 32,767 bind parameters. 3,100 new
// fingerprints is 37,200 on the candidate upsert alone, and a window that
// cannot commit never advances the cursor.
const burst = Array.from({ length: 3_100 }, (_, i) => scanRow({ fingerprintHash: `7${i}` }))
return Effect.gen(function* () {
const errors = yield* ErrorsService
const database = yield* Database
yield* TestClock.setTime(TICK_MS)
yield* seedIssue(asIssueId(randomUUID()))

const result = yield* errors.runTick()
assert.strictEqual(result.issuesTouched, 3_100)
assert.strictEqual(result.incidentsOpened, 3_100)

const cursor = yield* database.execute((db) =>
db.select().from(errorTickStates).where(eq(errorTickStates.orgId, ORG)),
)
assert.strictEqual(cursor[0]?.processedThrough.getTime(), TICK_MS - 60_000)
// Every chunk landed, not just the ones a counter reports: one `created`
// event per issue, and no promoted candidate left behind.
const created = yield* database.execute((db) =>
db.select().from(errorIssueEvents).where(eq(errorIssueEvents.type, "created")),
)
assert.lengthOf(created, 3_100)
assert.lengthOf(yield* database.execute((db) => db.select().from(errorFingerprintCandidates)), 0)

// The same burst a minute later lands on the incidents it just opened.
yield* TestClock.setTime(TICK_MS + 60_000)
const ongoing = yield* errors.runTick()
assert.strictEqual(ongoing.issuesTouched, 3_100)
assert.strictEqual(ongoing.incidentsOpened, 0)

// Thirty quiet minutes later every one of those incidents goes stale in
// the same window.
burst.length = 0
yield* TestClock.setTime(TICK_MS + 33 * 60_000)
const quiet = yield* runTicksUntilCaughtUp()
assert.strictEqual(quiet.incidentsResolved, 3_100)
}).pipe(Effect.provide(makeErrorsLayer(() => burst)))
})

it.effect("a window applied without the cursor claim commits nothing", () => {
const rows = [scanRow()]
return Effect.gen(function* () {
Expand Down
Loading
Loading