Skip to content

Commit

Permalink
Merge pull request #590 from share/flaky-query-test-fix
Browse files Browse the repository at this point in the history
✅ Fix flaky tests
  • Loading branch information
alecgibson committed Feb 16, 2023
2 parents b84290f + 7681077 commit bd7ec3f
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions test/client/query-subscribe.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,18 +187,25 @@ module.exports = function(options) {
}
], function(err) {
if (err) return done(err);

var wait = 2;
function finish() {
if (--wait) return;
expect(util.pluck(query.results, 'id')).to.eql(['fido', 'spot', 'taco']);
done();
}

var query = connection.createSubscribeQuery('dogs', matchAllDbQuery, null, function(err) {
if (err) return done(err);
connection.close();
connection2.get('dogs', 'taco').on('error', done).create({age: 2});
process.nextTick(function() {
backend.connect(connection);
query.on('ready', finish);
});
});
query.on('error', done);
query.on('insert', function() {
done();
});
query.on('insert', finish);
});
});

Expand Down Expand Up @@ -234,11 +241,14 @@ module.exports = function(options) {
], function(error) {
if (error) return done(error);
backend.connect(connection);
query.once('ready', function() {
finish();
});
});
});
});

var wait = 2;
var wait = 3;
function finish() {
if (--wait) return;
var results = util.sortById(query.results);
Expand Down

0 comments on commit bd7ec3f

Please sign in to comment.