Skip to content

Try to address flaky database transaction tests. #235

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 18, 2017
Merged
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
35 changes: 29 additions & 6 deletions packages/database/test/transaction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,20 @@ import firebase from '@firebase/app';
import '../index';

describe('Transaction Tests', function() {
// Tests that use hijackHash() should set restoreHash to the restore function
// and be sure to call it (and set restoreHash back to null) before the test
// exits. In the case that the test fails to do so, we'll log a warning and
// call restoreHash() manually to ensure subsequent tests aren't affected.
let restoreHash = null;

afterEach(() => {
if (restoreHash) {
console.warn("Prior test didn't properly call restoreHash()!");
restoreHash();
restoreHash = null;
}
});

it('New value is immediately visible.', function() {
const node = getRandomNode() as Reference;
node.child('foo').transaction(function() {
Expand All @@ -45,7 +59,7 @@ describe('Transaction Tests', function() {
expect(val).to.equal(42);
});

it.skip('Event is raised for new value.', function() {
it('Event is raised for new value.', function() {
const node = getRandomNode() as Reference;
const fooNode = node.child('foo');
const eventHelper = eventTestHelper([[fooNode, ['value', '']]]);
Expand Down Expand Up @@ -475,7 +489,7 @@ describe('Transaction Tests', function() {
});

it('Transaction aborts after 25 retries.', function(done) {
const restoreHash = hijackHash(function() {
restoreHash = hijackHash(function() {
return 'duck, duck, goose.';
});

Expand All @@ -492,6 +506,7 @@ describe('Transaction Tests', function() {
expect(committed).to.equal(false);
expect(tries).to.equal(25);
restoreHash();
restoreHash = null;
done();
}
);
Expand Down Expand Up @@ -526,7 +541,7 @@ describe('Transaction Tests', function() {
const node = getRandomNode() as Reference;
let fooTransactionDone = false;
let barTransactionDone = false;
const restoreHash = hijackHash(function() {
restoreHash = hijackHash(function() {
return 'foobar';
});

Expand Down Expand Up @@ -569,6 +584,7 @@ describe('Transaction Tests', function() {
expect(fooTransactionDone).to.equal(true);
expect(barTransactionDone).to.equal(false);
restoreHash();
restoreHash = null;
});

it('Test transaction on wacky unicode data.', function(done) {
Expand Down Expand Up @@ -793,11 +809,14 @@ describe('Transaction Tests', function() {

// This test is meant to ensure that with applyLocally=false, while the transaction is outstanding, we continue
// to get events from other clients.
it('Transaction without local events (2)', function(done) {
// TODO(mikelehen): Unfortunately this test is currently flaky. It's inherently a racey test since it's
// trying to do 4 sets before the transaction retries 25 times (and fails), using two different connections.
// Disabling for now until we rework the approach.
it.skip('Transaction without local events (2)', function(done) {
const refPair = getRandomNode(2) as Reference[],
ref1 = refPair[0],
ref2 = refPair[1];
const restoreHash = hijackHash(function() {
restoreHash = hijackHash(function() {
return 'badhash';
});
const SETS = 4;
Expand All @@ -818,6 +837,7 @@ describe('Transaction Tests', function() {

if (current === SETS - 1) {
restoreHash();
restoreHash = null;
}
return 'txn result';
},
Expand Down Expand Up @@ -856,7 +876,10 @@ describe('Transaction Tests', function() {
}
expect(events[SETS]).to.equal('txn result');

restoreHash();
if (restoreHash) {
restoreHash();
restoreHash = null;
}
done();
});
}
Expand Down