Skip to content

Commit f86f7de

Browse files
committed
Update transactions.test.ts
1 parent ed9fedf commit f86f7de

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

packages/firestore/test/integration/api/transactions.test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,30 @@ apiDescribe('Database transactions', (persistence: boolean) => {
629629
});
630630
});
631631

632+
it('retries when document already exists', () => {
633+
return withTestDb(persistence, async db => {
634+
let retryCounter = 0;
635+
const docRef = doc(collection(db, 'nonexistent'));
636+
637+
await runTransaction(db, async transaction => {
638+
++retryCounter;
639+
const snap1 = await transaction.get(docRef);
640+
641+
if (retryCounter === 1) {
642+
expect(snap1.exists()).to.be.false;
643+
// On the first attemp, create a doc before transaction.set(), so that
644+
// the transaction fails with "already-exists" error, and retries.
645+
await setDoc(docRef, { count: 1 });
646+
}
647+
648+
transaction.set(docRef, { count: 2 });
649+
});
650+
expect(retryCounter).to.equal(2);
651+
const result = await getDoc(docRef);
652+
expect(result.get('count')).to.equal(2);
653+
});
654+
});
655+
632656
it('are successful with no transaction operations', () => {
633657
return withTestDb(persistence, db => runTransaction(db, async () => {}));
634658
});

0 commit comments

Comments
 (0)