Check that transaction is not completed before attempting rollback

Signed-off-by: Eric Peterson <ericpeterson@spotify.com>
This commit is contained in:
Eric Peterson
2023-04-10 11:12:57 +02:00
parent acb9ae3672
commit b4bbf9e18e
2 changed files with 5 additions and 4 deletions
@@ -23,6 +23,7 @@ describe('PgSearchEngineIndexer', () => {
const tx = {
rollback: jest.fn(),
commit: jest.fn(),
isCompleted: jest.fn(),
} as any;
let database: jest.Mocked<DatabaseStore>;
let indexer: PgSearchEngineIndexer;
@@ -37,6 +38,7 @@ describe('PgSearchEngineIndexer', () => {
completeInsert: jest.fn(),
prepareInsert: jest.fn(),
};
tx.isCompleted.mockReturnValue(false);
indexer = new PgSearchEngineIndexer({
batchSize: 100,
type: 'my-type',
@@ -113,11 +113,10 @@ export class PgSearchEngineIndexer extends BatchSearchEngineIndexer {
return;
}
try {
this.tx!.rollback(error);
} catch {
// Unlikely! It was likely rolled back earlier.
if (!this.tx!.isCompleted()) {
await this.tx!.rollback(error);
}
done(error);
}
}