Skip to content
Open
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
16 changes: 16 additions & 0 deletions server/account/src/__tests__/mongo.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1011,6 +1011,22 @@ describe('MongoAccountDB', () => {
)
})

it('should get workspace for all operations including pending-deletion', async () => {
await accountDb.getPendingWorkspace('', version, 'all', processingTimeoutMs)

// The query should match pending-deletion / deleting workspaces too
const callArgs = (accountDb.workspace.collection.findOneAndUpdate as jest.Mock).mock.calls[0][0]
const orClauses = callArgs.$and[1].$or
const flatOrs = orClauses.flatMap((c: any) => (c.$or ? c.$or : [c]))
const deletingClause = flatOrs.find(
(c: any) => c['status.mode']?.$in?.includes('pending-deletion')
)
expect(deletingClause).toBeDefined()
expect(deletingClause['status.mode'].$in).toEqual(
expect.arrayContaining(['pending-deletion', 'deleting'])
)
})

it('should get workspace for all+backup operations', async () => {
await accountDb.getPendingWorkspace('', version, 'all+backup', processingTimeoutMs)

Expand Down
5 changes: 3 additions & 2 deletions server/account/src/__tests__/postgres.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -795,10 +795,11 @@ describe('PostgresAccountDB', () => {
OR
(
(s.is_disabled = FALSE OR s.is_disabled IS NULL)
AND s.mode = 'upgrading'
AND s.mode = 'upgrading'
)
)
)
OR s.mode IN ('pending-deletion', 'deleting')
)
AND s.mode <> 'manual-creation'
AND (s.processing_attempts IS NULL OR s.processing_attempts <= 3)
AND (s.last_processing_time IS NULL OR s.last_processing_time < $5)
Expand Down
2 changes: 1 addition & 1 deletion server/account/src/collections/mongo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,7 @@ export class MongoAccountDB implements AccountDB {
operationQuery = { $or: pendingUpgradeQuery }
break
case 'all':
operationQuery = { $or: [...pendingCreationQuery, ...pendingUpgradeQuery] }
operationQuery = { $or: [...pendingCreationQuery, ...pendingUpgradeQuery, ...deletingQuery] }
break
case 'all+backup':
operationQuery = {
Expand Down
4 changes: 1 addition & 3 deletions server/account/src/collections/postgres/postgres.ts
Original file line number Diff line number Diff line change
Expand Up @@ -999,7 +999,7 @@ export class PostgresAccountDB implements AccountDB {
operationSql = pendingUpgradeSql
break
case 'all':
operationSql = `(${pendingCreationSql} OR ${pendingUpgradeSql})`
operationSql = `(${pendingCreationSql} OR ${pendingUpgradeSql} OR ${deletingSql})`
break
case 'all+backup':
operationSql = `(${pendingCreationSql} OR ${pendingUpgradeSql} OR ${migrationSql} OR ${archivingSql} OR ${restoringSql} OR ${deletingSql})`
Expand All @@ -1015,8 +1015,6 @@ export class PostgresAccountDB implements AccountDB {
}
whereChunks.push(operationSql)

// TODO: support returning pending deletion workspaces when we will actually want
// to clear them with the worker.
whereChunks.push("s.mode <> 'manual-creation'")
whereChunks.push('(s.processing_attempts IS NULL OR s.processing_attempts <= 3)')
whereChunks.push(`(s.last_processing_time IS NULL OR s.last_processing_time < $${values.length + 1})`)
Expand Down