Skip to content

Commit bbdfbe1

Browse files
authored
Add error handlers in tests to try and find source of flakey test (#325)
1 parent 1782818 commit bbdfbe1

File tree

1 file changed

+61
-39
lines changed

1 file changed

+61
-39
lines changed

test/client/query-subscribe.js

+61-39
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ module.exports = function(options) {
1515
var connection = this.backend.connect();
1616
var query = connection.createSubscribeQuery('dogs', this.matchAllDbQuery, null, function(err) {
1717
if (err) return done(err);
18-
connection.get('dogs', 'fido').create({age: 3});
18+
connection.get('dogs', 'fido').on('error', done).create({age: 3});
1919
});
20+
query.on('error', done);
2021
query.on('insert', function(docs, index) {
2122
expect(util.pluck(docs, 'id')).eql(['fido']);
2223
expect(util.pluck(docs, 'data')).eql([{age: 3}]);
@@ -32,17 +33,18 @@ module.exports = function(options) {
3233
var matchAllDbQuery = this.matchAllDbQuery;
3334
async.parallel([
3435
function(cb) {
35-
connection.get('dogs', 'fido').create({age: 3}, cb);
36+
connection.get('dogs', 'fido').on('error', done).create({age: 3}, cb);
3637
},
3738
function(cb) {
38-
connection.get('dogs', 'spot').create({age: 5}, cb);
39+
connection.get('dogs', 'spot').on('error', done).create({age: 5}, cb);
3940
}
4041
], function(err) {
4142
if (err) return done(err);
4243
var query = connection.createSubscribeQuery('dogs', matchAllDbQuery, null, function(err) {
4344
if (err) return done(err);
44-
connection.get('dogs', 'taco').create({age: 2});
45+
connection.get('dogs', 'taco').on('error', done).create({age: 2});
4546
});
47+
query.on('error', done);
4648
query.on('insert', function(docs, index) {
4749
expect(util.pluck(docs, 'id')).eql(['taco']);
4850
expect(util.pluck(docs, 'data')).eql([{age: 2}]);
@@ -60,17 +62,18 @@ module.exports = function(options) {
6062
var matchAllDbQuery = this.matchAllDbQuery;
6163
async.parallel([
6264
function(cb) {
63-
connection.get('dogs', 'fido').create({age: 3}, cb);
65+
connection.get('dogs', 'fido').on('error', done).create({age: 3}, cb);
6466
},
6567
function(cb) {
66-
connection.get('dogs', 'spot').create({age: 5}, cb);
68+
connection.get('dogs', 'spot').on('error', done).create({age: 5}, cb);
6769
}
6870
], function(err) {
6971
if (err) return done(err);
7072
var query = connection.createSubscribeQuery('dogs', matchAllDbQuery, null, function(err) {
7173
if (err) return done(err);
7274
connection.get('dogs', 'fido').del();
7375
});
76+
query.on('error', done);
7477
query.on('remove', function(docs, index) {
7578
expect(util.pluck(docs, 'id')).eql(['fido']);
7679
expect(util.pluck(docs, 'data')).eql([undefined]);
@@ -89,17 +92,18 @@ module.exports = function(options) {
8992
var matchAllDbQuery = this.matchAllDbQuery;
9093
async.parallel([
9194
function(cb) {
92-
connection1.get('dogs', 'fido').create({age: 3}, cb);
95+
connection1.get('dogs', 'fido').on('error', done).create({age: 3}, cb);
9396
},
9497
function(cb) {
95-
connection1.get('dogs', 'spot').create({age: 5}, cb);
98+
connection1.get('dogs', 'spot').on('error', done).create({age: 5}, cb);
9699
}
97100
], function(err) {
98101
if (err) return done(err);
99102
var query = connection2.createSubscribeQuery('dogs', matchAllDbQuery, null, function(err) {
100103
if (err) return done(err);
101104
connection1.get('dogs', 'fido').del();
102105
});
106+
query.on('error', done);
103107
var removed = false;
104108
connection2.get('dogs', 'fido').on('del', function() {
105109
expect(removed).equal(true);
@@ -123,20 +127,21 @@ module.exports = function(options) {
123127
var matchAllDbQuery = this.matchAllDbQuery;
124128
async.parallel([
125129
function(cb) {
126-
connection.get('dogs', 'fido').create({age: 3}, cb);
130+
connection.get('dogs', 'fido').on('error', done).create({age: 3}, cb);
127131
},
128132
function(cb) {
129-
connection.get('dogs', 'spot').create({age: 5}, cb);
133+
connection.get('dogs', 'spot').on('error', done).create({age: 5}, cb);
130134
}
131135
], function(err) {
132136
if (err) return done(err);
133137
var query = connection.createSubscribeQuery('dogs', matchAllDbQuery, null, function(err) {
134138
if (err) return done(err);
135139
query.destroy(function(err) {
136140
if (err) return done(err);
137-
connection2.get('dogs', 'taco').create({age: 2}, done);
141+
connection2.get('dogs', 'taco').on('error', done).create({age: 2}, done);
138142
});
139143
});
144+
query.on('error', done);
140145
query.on('insert', function() {
141146
done();
142147
});
@@ -149,18 +154,19 @@ module.exports = function(options) {
149154
var matchAllDbQuery = this.matchAllDbQuery;
150155
async.parallel([
151156
function(cb) {
152-
connection.get('dogs', 'fido').create({age: 3}, cb);
157+
connection.get('dogs', 'fido').on('error', done).create({age: 3}, cb);
153158
},
154159
function(cb) {
155-
connection.get('dogs', 'spot').create({age: 5}, cb);
160+
connection.get('dogs', 'spot').on('error', done).create({age: 5}, cb);
156161
}
157162
], function(err) {
158163
if (err) return done(err);
159164
var query = connection.createSubscribeQuery('dogs', matchAllDbQuery, null, function(err) {
160165
if (err) return done(err);
161166
connection.close();
162-
connection2.get('dogs', 'taco').create({age: 2}, done);
167+
connection2.get('dogs', 'taco').on('error', done).create({age: 2}, done);
163168
});
169+
query.on('error', done);
164170
query.on('insert', function() {
165171
done();
166172
});
@@ -174,21 +180,22 @@ module.exports = function(options) {
174180
var matchAllDbQuery = this.matchAllDbQuery;
175181
async.parallel([
176182
function(cb) {
177-
connection.get('dogs', 'fido').create({age: 3}, cb);
183+
connection.get('dogs', 'fido').on('error', done).create({age: 3}, cb);
178184
},
179185
function(cb) {
180-
connection.get('dogs', 'spot').create({age: 5}, cb);
186+
connection.get('dogs', 'spot').on('error', done).create({age: 5}, cb);
181187
}
182188
], function(err) {
183189
if (err) return done(err);
184190
var query = connection.createSubscribeQuery('dogs', matchAllDbQuery, null, function(err) {
185191
if (err) return done(err);
186192
connection.close();
187-
connection2.get('dogs', 'taco').create({age: 2});
193+
connection2.get('dogs', 'taco').on('error', done).create({age: 2});
188194
process.nextTick(function() {
189195
backend.connect(connection);
190196
});
191197
});
198+
query.on('error', done);
192199
query.on('insert', function() {
193200
done();
194201
});
@@ -202,10 +209,10 @@ module.exports = function(options) {
202209
var matchAllDbQuery = this.matchAllDbQuery;
203210
async.parallel([
204211
function(cb) {
205-
connection.get('dogs', 'fido').create({age: 3}, cb);
212+
connection.get('dogs', 'fido').on('error', done).create({age: 3}, cb);
206213
},
207214
function(cb) {
208-
connection.get('dogs', 'spot').create({age: 5}, cb);
215+
connection.get('dogs', 'spot').on('error', done).create({age: 5}, cb);
209216
}
210217
], function(err) {
211218
if (err) return done(err);
@@ -215,12 +222,13 @@ module.exports = function(options) {
215222
connection2.get('dogs', 'fido').fetch(function(err) {
216223
if (err) return done(err);
217224
connection2.get('dogs', 'fido').del();
218-
connection2.get('dogs', 'taco').create({age: 2});
225+
connection2.get('dogs', 'taco').on('error', done).create({age: 2});
219226
process.nextTick(function() {
220227
backend.connect(connection);
221228
});
222229
});
223230
});
231+
query.on('error', done);
224232
var wait = 2;
225233
function finish() {
226234
if (--wait) return;
@@ -249,17 +257,18 @@ module.exports = function(options) {
249257
var matchAllDbQuery = this.matchAllDbQuery;
250258
async.parallel([
251259
function(cb) {
252-
connection.get('dogs', 'fido').create({age: 3}, cb);
260+
connection.get('dogs', 'fido').on('error', done).create({age: 3}, cb);
253261
},
254262
function(cb) {
255-
connection.get('dogs', 'spot').create({age: 5}, cb);
263+
connection.get('dogs', 'spot').on('error', done).create({age: 5}, cb);
256264
}
257265
], function(err) {
258266
if (err) return done(err);
259267
var query = connection.createSubscribeQuery('dogs', matchAllDbQuery, null, function(err) {
260268
if (err) return done(err);
261-
connection.get('dogs', 'taco').create({age: 2});
269+
connection.get('dogs', 'taco').on('error', done).create({age: 2});
262270
});
271+
query.on('error', done);
263272
query.on('insert', function(docs, index) {
264273
expect(util.pluck(docs, 'id')).eql(['taco']);
265274
expect(util.pluck(docs, 'data')).eql([{age: 2}]);
@@ -278,6 +287,7 @@ module.exports = function(options) {
278287
return false;
279288
};
280289
var query = connection.createSubscribeQuery('items', this.matchAllDbQuery, {pollDebounce: 1000});
290+
query.on('error', done);
281291
var batchSizes = [];
282292
var total = 0;
283293

@@ -287,7 +297,9 @@ module.exports = function(options) {
287297
if (total === 1) {
288298
// first write received by client. we're debouncing. create 9
289299
// more documents.
290-
for (var i = 1; i < 10; i++) connection.get('items', i.toString()).create({});
300+
for (var i = 1; i < 10; i++) {
301+
connection.get('items', i.toString()).on('error', done).create({});
302+
}
291303
}
292304
if (total === 10) {
293305
// first document is its own batch; then subsequent creates
@@ -300,7 +312,7 @@ module.exports = function(options) {
300312
// create an initial document. this will lead to the 'insert'
301313
// event firing the first time, while sharedb is definitely
302314
// debouncing
303-
connection.get('items', '0').create({});
315+
connection.get('items', '0').on('error', done).create({});
304316
});
305317

306318
it('db.pollDebounce option reduces subsequent poll interval', function(done) {
@@ -310,6 +322,7 @@ module.exports = function(options) {
310322
};
311323
this.backend.db.pollDebounce = 1000;
312324
var query = connection.createSubscribeQuery('items', this.matchAllDbQuery);
325+
query.on('error', done);
313326
var batchSizes = [];
314327
var total = 0;
315328

@@ -319,7 +332,9 @@ module.exports = function(options) {
319332
if (total === 1) {
320333
// first write received by client. we're debouncing. create 9
321334
// more documents.
322-
for (var i = 1; i < 10; i++) connection.get('items', i.toString()).create({});
335+
for (var i = 1; i < 10; i++) {
336+
connection.get('items', i.toString()).on('error', done).create({});
337+
}
323338
}
324339
if (total === 10) {
325340
// first document is its own batch; then subsequent creates
@@ -332,16 +347,17 @@ module.exports = function(options) {
332347
// create an initial document. this will lead to the 'insert'
333348
// event firing the first time, while sharedb is definitely
334349
// debouncing
335-
connection.get('items', '0').create({});
350+
connection.get('items', '0').on('error', done).create({});
336351
});
337352

338353
it('pollInterval updates a subscribed query after an unpublished create', function(done) {
339354
var connection = this.backend.connect();
340355
this.backend.suppressPublish = true;
341356
var query = connection.createSubscribeQuery('dogs', this.matchAllDbQuery, {pollInterval: 50}, function(err) {
342357
if (err) return done(err);
343-
connection.get('dogs', 'fido').create({});
358+
connection.get('dogs', 'fido').on('error', done).create({});
344359
});
360+
query.on('error', done);
345361
query.on('insert', function(docs) {
346362
expect(util.pluck(docs, 'id')).eql(['fido']);
347363
done();
@@ -354,8 +370,9 @@ module.exports = function(options) {
354370
this.backend.db.pollInterval = 50;
355371
var query = connection.createSubscribeQuery('dogs', this.matchAllDbQuery, null, function(err) {
356372
if (err) return done(err);
357-
connection.get('dogs', 'fido').create({});
373+
connection.get('dogs', 'fido').on('error', done).create({});
358374
});
375+
query.on('error', done);
359376
query.on('insert', function(docs) {
360377
expect(util.pluck(docs, 'id')).eql(['fido']);
361378
done();
@@ -368,12 +385,13 @@ module.exports = function(options) {
368385
var count = 0;
369386
var query = connection.createSubscribeQuery('dogs', this.matchAllDbQuery, {pollInterval: 50}, function(err) {
370387
if (err) return done(err);
371-
connection.get('dogs', count.toString()).create({});
388+
connection.get('dogs', count.toString()).on('error', done).create({});
372389
});
390+
query.on('error', done);
373391
query.on('insert', function() {
374392
count++;
375393
if (count === 3) return done();
376-
connection.get('dogs', count.toString()).create({});
394+
connection.get('dogs', count.toString()).on('error', done).create({});
377395
});
378396
});
379397

@@ -391,6 +409,7 @@ module.exports = function(options) {
391409
expect(query.extra).eql({colors: ['brown', 'gold']});
392410
done();
393411
});
412+
query.on('error', done);
394413
});
395414

396415
it('query extra is updated on change', function(done) {
@@ -413,22 +432,23 @@ module.exports = function(options) {
413432
expect(extra).eql(1);
414433
expect(query.extra).eql(1);
415434
});
435+
query.on('error', done);
416436
query.on('extra', function(extra) {
417437
expect(extra).eql(2);
418438
expect(query.extra).eql(2);
419439
done();
420440
});
421-
connection.get('dogs', 'fido').create({age: 3});
441+
connection.get('dogs', 'fido').on('error', done).create({age: 3});
422442
});
423443

424444
it('changing a filtered property removes from a subscribed query', function(done) {
425445
var connection = this.backend.connect();
426446
async.parallel([
427447
function(cb) {
428-
connection.get('dogs', 'fido').create({age: 3}, cb);
448+
connection.get('dogs', 'fido').on('error', done).create({age: 3}, cb);
429449
},
430450
function(cb) {
431-
connection.get('dogs', 'spot').create({age: 3}, cb);
451+
connection.get('dogs', 'spot').on('error', done).create({age: 3}, cb);
432452
}
433453
], function(err) {
434454
if (err) return done(err);
@@ -440,6 +460,7 @@ module.exports = function(options) {
440460
expect(util.pluck(sorted, 'data')).eql([{age: 3}, {age: 3}]);
441461
connection.get('dogs', 'fido').submitOp({p: ['age'], na: 2});
442462
});
463+
query.on('error', done);
443464
query.on('remove', function(docs, index) {
444465
expect(util.pluck(docs, 'id')).eql(['fido']);
445466
expect(util.pluck(docs, 'data')).eql([{age: 5}]);
@@ -456,10 +477,10 @@ module.exports = function(options) {
456477
var connection = this.backend.connect();
457478
async.parallel([
458479
function(cb) {
459-
connection.get('dogs', 'fido').create({age: 3}, cb);
480+
connection.get('dogs', 'fido').on('error', done).create({age: 3}, cb);
460481
},
461482
function(cb) {
462-
connection.get('dogs', 'spot').create({age: 5}, cb);
483+
connection.get('dogs', 'spot').on('error', done).create({age: 5}, cb);
463484
}
464485
], function(err) {
465486
if (err) return done(err);
@@ -471,6 +492,7 @@ module.exports = function(options) {
471492
expect(util.pluck(sorted, 'data')).eql([{age: 3}]);
472493
connection.get('dogs', 'spot').submitOp({p: ['age'], na: -2});
473494
});
495+
query.on('error', done);
474496
query.on('insert', function(docs, index) {
475497
expect(util.pluck(docs, 'id')).eql(['spot']);
476498
expect(util.pluck(docs, 'data')).eql([{age: 3}]);
@@ -488,10 +510,10 @@ module.exports = function(options) {
488510

489511
async.parallel([
490512
function(cb) {
491-
connection.get('dogs', 'fido').create({age: 3}, cb);
513+
connection.get('dogs', 'fido').on('error', done).create({age: 3}, cb);
492514
},
493515
function(cb) {
494-
connection.get('dogs', 'spot').create({age: 5}, cb);
516+
connection.get('dogs', 'spot').on('error', done).create({age: 5}, cb);
495517
}
496518
], function(err) {
497519
if (err) return done(err);
@@ -506,7 +528,7 @@ module.exports = function(options) {
506528
expect(util.pluck(results, 'data')).eql([{age: 3}, {age: 5}]);
507529
connection.get('dogs', 'spot').submitOp({p: ['age'], na: -3});
508530
});
509-
531+
query.on('error', done);
510532
query.on('move', function(docs, from, to) {
511533
expect(docs.length).eql(1);
512534
expect(from).a('number');

0 commit comments

Comments
 (0)