f9fd3e68ca
* cleanup repeat process all * wip * skip actor search test * skip actor search test * tweak processAll * decrease wait to 1 sec * repo_blob -> record_blob * simplify backlink linkTo * return repo_root to one row * sequence before updating repo_root * invite code forUser -> forAccount * ipld_block -> repo_block * use lru-cache fetchMethod * move did_cache to own db * better error handling on did cache * drop did_handle * fix sequencer wait time * debug * debug * more debug * check something * fix bday paradox * fix bday paradox * tidy up pds service auth * rm skipped test * retry http * tidy * improve fanout error handling * fix test * return signing key in did-web * more tests * tidy serivce auth checks * user_account -> account * remove inviteNote * keypair per repo * use an lru cache for keypairs as well * clean up repo * wip * wrap up accoutn manager * tidy * tidy * fix tests * fix disabled codes * fix appview tests * add note * set pragmas * tidy account manager getDb * rename pref transactor * user pref -> account pref * handle blob imports * tidy imports * add reserveSigningKey * wip transferAccount * clean up transferAccount * tests * tidy * tidy * configure entryway url on pds * handle entryway in pds admin endpoints * make importRepo temp * fix imports * make email optional on pds when using entryway * handle diffs * handle pds entryway usage for server, identity, admin endpoints * pds support for credentials from entryway * setup pds tests w/ entryway service * tidy * tidy * update entryway version * wip * test handle updates w/ entryway * split account table into two * tidy * tweak scripts * tidy tests * tidy * better config for actorstore & dbs * clean up cfg more * reorg actorstore fs layout * handle erros on actor db create * pr tidy & fix accoutn deletion test * pr feedback * fix bad merge * unskip test * fix subscribe repos tests * tidy repo root tables * tidy * fix tests * tidy delete tokens * tidy account getters * tidy * bulk deletesg * increase chunk size * handle racing refreshes * wip * fix auth test * invert import flow * clean up actor store on create account failure * tweak sequencer * prevent invite code races on createAccount * rm note * add back in race protection on getAccountInviteCodes * start feature branch * deleted app migration table * patch up new auth test * rm note * g * create accoutn delegated from entryway * tidy * fix test * change plcOp type to unknown * small fixes * sync up w entryway branch * Use proper error when authed account is not found (#1799) provide proper error when account not found in access-takedown check * build branch * build on ghcr * tweak service file * tweak service file * change where we save reserved keys * no tmp dir in blobstore either * fix blobstore temp location again * handle repeat record_blobs * create account before submitting plc op & undo if fail * small tweak * limit the number of local records * push out empty commit on transfer * fix issue with record_blob * add push blob endpoint * Set and validate token audiences on pds v2 (#1793) set and validate token audience on pds v2 * merge * include entryway did on tests * build branch * fix cache issue * xrpc server blob limit * put correct bytes * add auth to routes * handle quarantining/unquarantining a blob that does not exist * tidy * fix transfer tests * fix email request routes for entryway * PDS v2 entryway account deletion (#1819) * add admin lexicon for account deletion * implement admin account deletion endpoint * fix entryway proxying on account email checks * proxy to entryway for acct deletion * read-after-write sanity check * tweak * wip * finish refactor * fix test schema * application retry logic for busy * pr feedback * rm lru-cache * fix test pg schema * fix transfer test * Sqlite instrumentation for pds v2 (#1838) * sqlite instrumentation * build * remove build * dont reimport blobs * send ticks during import * close on error * catch handle validation error * add log * fix test * return emailConfirmedAt on getAccountInfo * Upgrade sharp on pds v2 (#1863) upgrade sharp to 0.32.6 * read all bytes before parsing car * Async car reader (#1867) * asynchronously read in car * dont buffer car * tweak * Gracefully handle indexing of invalid records (#1853) * gracefully handle indexing of invalid records * fix repo tests * Fix role auth for access-or-role verifier, getBlob check on actor takedowns (#1869) fix role auth for access-or-role verifier, fix getBlob actor takedown check * better cleanup of actor-stores * add ability to not ensure leaves * tidy * allow did:web transfer * Migration utility for actor-store (#1873) beginnings of helper for migrating all actors Co-authored-by: Devin Ivy <devinivy@gmail.com> * base case for findBlobRefs * App-level retries for sqlite on pds (#1871) * revamp retry helper to be more flexible re: backoff strategies * sqlite timeout helper * ensure sqlite wal on db creation/migration rather than every open * layer retries for sqlite on writes outside transactions on pds * tidy * fix up lockfile * tidy * fix lex codegen * fix timing bug in threadgate test * No-op update handling (#1916) do no produce commits on no-op updates * Retry on all SQLITE_BUSY error codes (#1917) retry on all sqlite_busy error codes * Pds v2 ensure sqlite ready (#1918) ensure sqlite is ready before making queries * try something * tidy * dont build branch --------- Co-authored-by: Devin Ivy <devinivy@gmail.com>
165 lines
3.9 KiB
TypeScript
165 lines
3.9 KiB
TypeScript
import { TestNetworkNoAppView } from '@atproto/dev-env'
|
|
import { AccountDb } from '../src/account-manager/db'
|
|
|
|
describe('db', () => {
|
|
let network: TestNetworkNoAppView
|
|
let db: AccountDb
|
|
|
|
beforeAll(async () => {
|
|
network = await TestNetworkNoAppView.create({
|
|
dbPostgresSchema: 'db',
|
|
})
|
|
db = network.pds.ctx.accountManager.db
|
|
})
|
|
|
|
afterAll(async () => {
|
|
await network.close()
|
|
})
|
|
|
|
it('commits changes', async () => {
|
|
const result = await db.transaction(async (dbTxn) => {
|
|
return await dbTxn.db
|
|
.insertInto('repo_root')
|
|
.values({
|
|
did: 'x',
|
|
cid: 'x',
|
|
rev: 'x',
|
|
indexedAt: 'bad-date',
|
|
})
|
|
.returning('did')
|
|
.executeTakeFirst()
|
|
})
|
|
|
|
if (!result) {
|
|
return expect(result).toBeTruthy()
|
|
}
|
|
|
|
expect(result.did).toEqual('x')
|
|
|
|
const row = await db.db
|
|
.selectFrom('repo_root')
|
|
.selectAll()
|
|
.where('did', '=', 'x')
|
|
.executeTakeFirst()
|
|
|
|
expect(row).toEqual({
|
|
did: 'x',
|
|
cid: 'x',
|
|
rev: 'x',
|
|
indexedAt: 'bad-date',
|
|
})
|
|
})
|
|
|
|
it('rolls-back changes on failure', async () => {
|
|
const promise = db.transaction(async (dbTxn) => {
|
|
await dbTxn.db
|
|
.insertInto('repo_root')
|
|
.values({
|
|
did: 'y',
|
|
cid: 'y',
|
|
rev: 'y',
|
|
indexedAt: 'bad-date',
|
|
})
|
|
.returning('did')
|
|
.executeTakeFirst()
|
|
|
|
throw new Error('Oops!')
|
|
})
|
|
|
|
await expect(promise).rejects.toThrow('Oops!')
|
|
|
|
const row = await db.db
|
|
.selectFrom('repo_root')
|
|
.selectAll()
|
|
.where('did', '=', 'y')
|
|
.executeTakeFirst()
|
|
|
|
expect(row).toBeUndefined()
|
|
})
|
|
|
|
it('indicates isTransaction', async () => {
|
|
expect(db.isTransaction).toEqual(false)
|
|
|
|
await db.transaction(async (dbTxn) => {
|
|
expect(db.isTransaction).toEqual(false)
|
|
expect(dbTxn.isTransaction).toEqual(true)
|
|
})
|
|
|
|
expect(db.isTransaction).toEqual(false)
|
|
})
|
|
|
|
it('asserts transaction', async () => {
|
|
expect(() => db.assertTransaction()).toThrow('Transaction required')
|
|
|
|
await db.transaction(async (dbTxn) => {
|
|
expect(() => dbTxn.assertTransaction()).not.toThrow()
|
|
})
|
|
})
|
|
|
|
it('does not allow leaky transactions', async () => {
|
|
let leakedTx: AccountDb | undefined
|
|
|
|
const tx = db.transaction(async (dbTxn) => {
|
|
leakedTx = dbTxn
|
|
await dbTxn.db
|
|
.insertInto('repo_root')
|
|
.values({ cid: 'a', did: 'a', rev: 'a', indexedAt: 'bad-date' })
|
|
.execute()
|
|
throw new Error('test tx failed')
|
|
})
|
|
await expect(tx).rejects.toThrow('test tx failed')
|
|
|
|
const attempt = leakedTx?.db
|
|
.insertInto('repo_root')
|
|
.values({ cid: 'b', did: 'b', rev: 'b', indexedAt: 'bad-date' })
|
|
.execute()
|
|
await expect(attempt).rejects.toThrow('tx already failed')
|
|
|
|
const res = await db.db
|
|
.selectFrom('repo_root')
|
|
.selectAll()
|
|
.where('did', 'in', ['a', 'b'])
|
|
.execute()
|
|
|
|
expect(res.length).toBe(0)
|
|
})
|
|
|
|
it('ensures all inflight queries are rolled back', async () => {
|
|
let promise: Promise<unknown> | undefined = undefined
|
|
const names: string[] = []
|
|
try {
|
|
await db.transaction(async (dbTxn) => {
|
|
const queries: Promise<unknown>[] = []
|
|
for (let i = 0; i < 20; i++) {
|
|
const name = `user${i}`
|
|
const query = dbTxn.db
|
|
.insertInto('repo_root')
|
|
.values({
|
|
cid: name,
|
|
did: name,
|
|
rev: name,
|
|
indexedAt: 'bad-date',
|
|
})
|
|
.execute()
|
|
names.push(name)
|
|
queries.push(query)
|
|
}
|
|
promise = Promise.allSettled(queries)
|
|
throw new Error()
|
|
})
|
|
} catch (err) {
|
|
expect(err).toBeDefined()
|
|
}
|
|
if (promise) {
|
|
await promise
|
|
}
|
|
|
|
const res = await db.db
|
|
.selectFrom('repo_root')
|
|
.selectAll()
|
|
.where('did', 'in', names)
|
|
.execute()
|
|
expect(res.length).toBe(0)
|
|
})
|
|
})
|