@@ -15,8 +15,9 @@ module.exports = function(options) {
15
15
var connection = this . backend . connect ( ) ;
16
16
var query = connection . createSubscribeQuery ( 'dogs' , this . matchAllDbQuery , null , function ( err ) {
17
17
if ( err ) return done ( err ) ;
18
- connection . get ( 'dogs' , 'fido' ) . create ( { age : 3 } ) ;
18
+ connection . get ( 'dogs' , 'fido' ) . on ( 'error' , done ) . create ( { age : 3 } ) ;
19
19
} ) ;
20
+ query . on ( 'error' , done ) ;
20
21
query . on ( 'insert' , function ( docs , index ) {
21
22
expect ( util . pluck ( docs , 'id' ) ) . eql ( [ 'fido' ] ) ;
22
23
expect ( util . pluck ( docs , 'data' ) ) . eql ( [ { age : 3 } ] ) ;
@@ -32,17 +33,18 @@ module.exports = function(options) {
32
33
var matchAllDbQuery = this . matchAllDbQuery ;
33
34
async . parallel ( [
34
35
function ( cb ) {
35
- connection . get ( 'dogs' , 'fido' ) . create ( { age : 3 } , cb ) ;
36
+ connection . get ( 'dogs' , 'fido' ) . on ( 'error' , done ) . create ( { age : 3 } , cb ) ;
36
37
} ,
37
38
function ( cb ) {
38
- connection . get ( 'dogs' , 'spot' ) . create ( { age : 5 } , cb ) ;
39
+ connection . get ( 'dogs' , 'spot' ) . on ( 'error' , done ) . create ( { age : 5 } , cb ) ;
39
40
}
40
41
] , function ( err ) {
41
42
if ( err ) return done ( err ) ;
42
43
var query = connection . createSubscribeQuery ( 'dogs' , matchAllDbQuery , null , function ( err ) {
43
44
if ( err ) return done ( err ) ;
44
- connection . get ( 'dogs' , 'taco' ) . create ( { age : 2 } ) ;
45
+ connection . get ( 'dogs' , 'taco' ) . on ( 'error' , done ) . create ( { age : 2 } ) ;
45
46
} ) ;
47
+ query . on ( 'error' , done ) ;
46
48
query . on ( 'insert' , function ( docs , index ) {
47
49
expect ( util . pluck ( docs , 'id' ) ) . eql ( [ 'taco' ] ) ;
48
50
expect ( util . pluck ( docs , 'data' ) ) . eql ( [ { age : 2 } ] ) ;
@@ -60,17 +62,18 @@ module.exports = function(options) {
60
62
var matchAllDbQuery = this . matchAllDbQuery ;
61
63
async . parallel ( [
62
64
function ( cb ) {
63
- connection . get ( 'dogs' , 'fido' ) . create ( { age : 3 } , cb ) ;
65
+ connection . get ( 'dogs' , 'fido' ) . on ( 'error' , done ) . create ( { age : 3 } , cb ) ;
64
66
} ,
65
67
function ( cb ) {
66
- connection . get ( 'dogs' , 'spot' ) . create ( { age : 5 } , cb ) ;
68
+ connection . get ( 'dogs' , 'spot' ) . on ( 'error' , done ) . create ( { age : 5 } , cb ) ;
67
69
}
68
70
] , function ( err ) {
69
71
if ( err ) return done ( err ) ;
70
72
var query = connection . createSubscribeQuery ( 'dogs' , matchAllDbQuery , null , function ( err ) {
71
73
if ( err ) return done ( err ) ;
72
74
connection . get ( 'dogs' , 'fido' ) . del ( ) ;
73
75
} ) ;
76
+ query . on ( 'error' , done ) ;
74
77
query . on ( 'remove' , function ( docs , index ) {
75
78
expect ( util . pluck ( docs , 'id' ) ) . eql ( [ 'fido' ] ) ;
76
79
expect ( util . pluck ( docs , 'data' ) ) . eql ( [ undefined ] ) ;
@@ -89,17 +92,18 @@ module.exports = function(options) {
89
92
var matchAllDbQuery = this . matchAllDbQuery ;
90
93
async . parallel ( [
91
94
function ( cb ) {
92
- connection1 . get ( 'dogs' , 'fido' ) . create ( { age : 3 } , cb ) ;
95
+ connection1 . get ( 'dogs' , 'fido' ) . on ( 'error' , done ) . create ( { age : 3 } , cb ) ;
93
96
} ,
94
97
function ( cb ) {
95
- connection1 . get ( 'dogs' , 'spot' ) . create ( { age : 5 } , cb ) ;
98
+ connection1 . get ( 'dogs' , 'spot' ) . on ( 'error' , done ) . create ( { age : 5 } , cb ) ;
96
99
}
97
100
] , function ( err ) {
98
101
if ( err ) return done ( err ) ;
99
102
var query = connection2 . createSubscribeQuery ( 'dogs' , matchAllDbQuery , null , function ( err ) {
100
103
if ( err ) return done ( err ) ;
101
104
connection1 . get ( 'dogs' , 'fido' ) . del ( ) ;
102
105
} ) ;
106
+ query . on ( 'error' , done ) ;
103
107
var removed = false ;
104
108
connection2 . get ( 'dogs' , 'fido' ) . on ( 'del' , function ( ) {
105
109
expect ( removed ) . equal ( true ) ;
@@ -123,20 +127,21 @@ module.exports = function(options) {
123
127
var matchAllDbQuery = this . matchAllDbQuery ;
124
128
async . parallel ( [
125
129
function ( cb ) {
126
- connection . get ( 'dogs' , 'fido' ) . create ( { age : 3 } , cb ) ;
130
+ connection . get ( 'dogs' , 'fido' ) . on ( 'error' , done ) . create ( { age : 3 } , cb ) ;
127
131
} ,
128
132
function ( cb ) {
129
- connection . get ( 'dogs' , 'spot' ) . create ( { age : 5 } , cb ) ;
133
+ connection . get ( 'dogs' , 'spot' ) . on ( 'error' , done ) . create ( { age : 5 } , cb ) ;
130
134
}
131
135
] , function ( err ) {
132
136
if ( err ) return done ( err ) ;
133
137
var query = connection . createSubscribeQuery ( 'dogs' , matchAllDbQuery , null , function ( err ) {
134
138
if ( err ) return done ( err ) ;
135
139
query . destroy ( function ( err ) {
136
140
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 ) ;
138
142
} ) ;
139
143
} ) ;
144
+ query . on ( 'error' , done ) ;
140
145
query . on ( 'insert' , function ( ) {
141
146
done ( ) ;
142
147
} ) ;
@@ -149,18 +154,19 @@ module.exports = function(options) {
149
154
var matchAllDbQuery = this . matchAllDbQuery ;
150
155
async . parallel ( [
151
156
function ( cb ) {
152
- connection . get ( 'dogs' , 'fido' ) . create ( { age : 3 } , cb ) ;
157
+ connection . get ( 'dogs' , 'fido' ) . on ( 'error' , done ) . create ( { age : 3 } , cb ) ;
153
158
} ,
154
159
function ( cb ) {
155
- connection . get ( 'dogs' , 'spot' ) . create ( { age : 5 } , cb ) ;
160
+ connection . get ( 'dogs' , 'spot' ) . on ( 'error' , done ) . create ( { age : 5 } , cb ) ;
156
161
}
157
162
] , function ( err ) {
158
163
if ( err ) return done ( err ) ;
159
164
var query = connection . createSubscribeQuery ( 'dogs' , matchAllDbQuery , null , function ( err ) {
160
165
if ( err ) return done ( err ) ;
161
166
connection . close ( ) ;
162
- connection2 . get ( 'dogs' , 'taco' ) . create ( { age : 2 } , done ) ;
167
+ connection2 . get ( 'dogs' , 'taco' ) . on ( 'error' , done ) . create ( { age : 2 } , done ) ;
163
168
} ) ;
169
+ query . on ( 'error' , done ) ;
164
170
query . on ( 'insert' , function ( ) {
165
171
done ( ) ;
166
172
} ) ;
@@ -174,21 +180,22 @@ module.exports = function(options) {
174
180
var matchAllDbQuery = this . matchAllDbQuery ;
175
181
async . parallel ( [
176
182
function ( cb ) {
177
- connection . get ( 'dogs' , 'fido' ) . create ( { age : 3 } , cb ) ;
183
+ connection . get ( 'dogs' , 'fido' ) . on ( 'error' , done ) . create ( { age : 3 } , cb ) ;
178
184
} ,
179
185
function ( cb ) {
180
- connection . get ( 'dogs' , 'spot' ) . create ( { age : 5 } , cb ) ;
186
+ connection . get ( 'dogs' , 'spot' ) . on ( 'error' , done ) . create ( { age : 5 } , cb ) ;
181
187
}
182
188
] , function ( err ) {
183
189
if ( err ) return done ( err ) ;
184
190
var query = connection . createSubscribeQuery ( 'dogs' , matchAllDbQuery , null , function ( err ) {
185
191
if ( err ) return done ( err ) ;
186
192
connection . close ( ) ;
187
- connection2 . get ( 'dogs' , 'taco' ) . create ( { age : 2 } ) ;
193
+ connection2 . get ( 'dogs' , 'taco' ) . on ( 'error' , done ) . create ( { age : 2 } ) ;
188
194
process . nextTick ( function ( ) {
189
195
backend . connect ( connection ) ;
190
196
} ) ;
191
197
} ) ;
198
+ query . on ( 'error' , done ) ;
192
199
query . on ( 'insert' , function ( ) {
193
200
done ( ) ;
194
201
} ) ;
@@ -202,10 +209,10 @@ module.exports = function(options) {
202
209
var matchAllDbQuery = this . matchAllDbQuery ;
203
210
async . parallel ( [
204
211
function ( cb ) {
205
- connection . get ( 'dogs' , 'fido' ) . create ( { age : 3 } , cb ) ;
212
+ connection . get ( 'dogs' , 'fido' ) . on ( 'error' , done ) . create ( { age : 3 } , cb ) ;
206
213
} ,
207
214
function ( cb ) {
208
- connection . get ( 'dogs' , 'spot' ) . create ( { age : 5 } , cb ) ;
215
+ connection . get ( 'dogs' , 'spot' ) . on ( 'error' , done ) . create ( { age : 5 } , cb ) ;
209
216
}
210
217
] , function ( err ) {
211
218
if ( err ) return done ( err ) ;
@@ -215,12 +222,13 @@ module.exports = function(options) {
215
222
connection2 . get ( 'dogs' , 'fido' ) . fetch ( function ( err ) {
216
223
if ( err ) return done ( err ) ;
217
224
connection2 . get ( 'dogs' , 'fido' ) . del ( ) ;
218
- connection2 . get ( 'dogs' , 'taco' ) . create ( { age : 2 } ) ;
225
+ connection2 . get ( 'dogs' , 'taco' ) . on ( 'error' , done ) . create ( { age : 2 } ) ;
219
226
process . nextTick ( function ( ) {
220
227
backend . connect ( connection ) ;
221
228
} ) ;
222
229
} ) ;
223
230
} ) ;
231
+ query . on ( 'error' , done ) ;
224
232
var wait = 2 ;
225
233
function finish ( ) {
226
234
if ( -- wait ) return ;
@@ -249,17 +257,18 @@ module.exports = function(options) {
249
257
var matchAllDbQuery = this . matchAllDbQuery ;
250
258
async . parallel ( [
251
259
function ( cb ) {
252
- connection . get ( 'dogs' , 'fido' ) . create ( { age : 3 } , cb ) ;
260
+ connection . get ( 'dogs' , 'fido' ) . on ( 'error' , done ) . create ( { age : 3 } , cb ) ;
253
261
} ,
254
262
function ( cb ) {
255
- connection . get ( 'dogs' , 'spot' ) . create ( { age : 5 } , cb ) ;
263
+ connection . get ( 'dogs' , 'spot' ) . on ( 'error' , done ) . create ( { age : 5 } , cb ) ;
256
264
}
257
265
] , function ( err ) {
258
266
if ( err ) return done ( err ) ;
259
267
var query = connection . createSubscribeQuery ( 'dogs' , matchAllDbQuery , null , function ( err ) {
260
268
if ( err ) return done ( err ) ;
261
- connection . get ( 'dogs' , 'taco' ) . create ( { age : 2 } ) ;
269
+ connection . get ( 'dogs' , 'taco' ) . on ( 'error' , done ) . create ( { age : 2 } ) ;
262
270
} ) ;
271
+ query . on ( 'error' , done ) ;
263
272
query . on ( 'insert' , function ( docs , index ) {
264
273
expect ( util . pluck ( docs , 'id' ) ) . eql ( [ 'taco' ] ) ;
265
274
expect ( util . pluck ( docs , 'data' ) ) . eql ( [ { age : 2 } ] ) ;
@@ -278,6 +287,7 @@ module.exports = function(options) {
278
287
return false ;
279
288
} ;
280
289
var query = connection . createSubscribeQuery ( 'items' , this . matchAllDbQuery , { pollDebounce : 1000 } ) ;
290
+ query . on ( 'error' , done ) ;
281
291
var batchSizes = [ ] ;
282
292
var total = 0 ;
283
293
@@ -287,7 +297,9 @@ module.exports = function(options) {
287
297
if ( total === 1 ) {
288
298
// first write received by client. we're debouncing. create 9
289
299
// 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
+ }
291
303
}
292
304
if ( total === 10 ) {
293
305
// first document is its own batch; then subsequent creates
@@ -300,7 +312,7 @@ module.exports = function(options) {
300
312
// create an initial document. this will lead to the 'insert'
301
313
// event firing the first time, while sharedb is definitely
302
314
// debouncing
303
- connection . get ( 'items' , '0' ) . create ( { } ) ;
315
+ connection . get ( 'items' , '0' ) . on ( 'error' , done ) . create ( { } ) ;
304
316
} ) ;
305
317
306
318
it ( 'db.pollDebounce option reduces subsequent poll interval' , function ( done ) {
@@ -310,6 +322,7 @@ module.exports = function(options) {
310
322
} ;
311
323
this . backend . db . pollDebounce = 1000 ;
312
324
var query = connection . createSubscribeQuery ( 'items' , this . matchAllDbQuery ) ;
325
+ query . on ( 'error' , done ) ;
313
326
var batchSizes = [ ] ;
314
327
var total = 0 ;
315
328
@@ -319,7 +332,9 @@ module.exports = function(options) {
319
332
if ( total === 1 ) {
320
333
// first write received by client. we're debouncing. create 9
321
334
// 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
+ }
323
338
}
324
339
if ( total === 10 ) {
325
340
// first document is its own batch; then subsequent creates
@@ -332,16 +347,17 @@ module.exports = function(options) {
332
347
// create an initial document. this will lead to the 'insert'
333
348
// event firing the first time, while sharedb is definitely
334
349
// debouncing
335
- connection . get ( 'items' , '0' ) . create ( { } ) ;
350
+ connection . get ( 'items' , '0' ) . on ( 'error' , done ) . create ( { } ) ;
336
351
} ) ;
337
352
338
353
it ( 'pollInterval updates a subscribed query after an unpublished create' , function ( done ) {
339
354
var connection = this . backend . connect ( ) ;
340
355
this . backend . suppressPublish = true ;
341
356
var query = connection . createSubscribeQuery ( 'dogs' , this . matchAllDbQuery , { pollInterval : 50 } , function ( err ) {
342
357
if ( err ) return done ( err ) ;
343
- connection . get ( 'dogs' , 'fido' ) . create ( { } ) ;
358
+ connection . get ( 'dogs' , 'fido' ) . on ( 'error' , done ) . create ( { } ) ;
344
359
} ) ;
360
+ query . on ( 'error' , done ) ;
345
361
query . on ( 'insert' , function ( docs ) {
346
362
expect ( util . pluck ( docs , 'id' ) ) . eql ( [ 'fido' ] ) ;
347
363
done ( ) ;
@@ -354,8 +370,9 @@ module.exports = function(options) {
354
370
this . backend . db . pollInterval = 50 ;
355
371
var query = connection . createSubscribeQuery ( 'dogs' , this . matchAllDbQuery , null , function ( err ) {
356
372
if ( err ) return done ( err ) ;
357
- connection . get ( 'dogs' , 'fido' ) . create ( { } ) ;
373
+ connection . get ( 'dogs' , 'fido' ) . on ( 'error' , done ) . create ( { } ) ;
358
374
} ) ;
375
+ query . on ( 'error' , done ) ;
359
376
query . on ( 'insert' , function ( docs ) {
360
377
expect ( util . pluck ( docs , 'id' ) ) . eql ( [ 'fido' ] ) ;
361
378
done ( ) ;
@@ -368,12 +385,13 @@ module.exports = function(options) {
368
385
var count = 0 ;
369
386
var query = connection . createSubscribeQuery ( 'dogs' , this . matchAllDbQuery , { pollInterval : 50 } , function ( err ) {
370
387
if ( err ) return done ( err ) ;
371
- connection . get ( 'dogs' , count . toString ( ) ) . create ( { } ) ;
388
+ connection . get ( 'dogs' , count . toString ( ) ) . on ( 'error' , done ) . create ( { } ) ;
372
389
} ) ;
390
+ query . on ( 'error' , done ) ;
373
391
query . on ( 'insert' , function ( ) {
374
392
count ++ ;
375
393
if ( count === 3 ) return done ( ) ;
376
- connection . get ( 'dogs' , count . toString ( ) ) . create ( { } ) ;
394
+ connection . get ( 'dogs' , count . toString ( ) ) . on ( 'error' , done ) . create ( { } ) ;
377
395
} ) ;
378
396
} ) ;
379
397
@@ -391,6 +409,7 @@ module.exports = function(options) {
391
409
expect ( query . extra ) . eql ( { colors : [ 'brown' , 'gold' ] } ) ;
392
410
done ( ) ;
393
411
} ) ;
412
+ query . on ( 'error' , done ) ;
394
413
} ) ;
395
414
396
415
it ( 'query extra is updated on change' , function ( done ) {
@@ -413,22 +432,23 @@ module.exports = function(options) {
413
432
expect ( extra ) . eql ( 1 ) ;
414
433
expect ( query . extra ) . eql ( 1 ) ;
415
434
} ) ;
435
+ query . on ( 'error' , done ) ;
416
436
query . on ( 'extra' , function ( extra ) {
417
437
expect ( extra ) . eql ( 2 ) ;
418
438
expect ( query . extra ) . eql ( 2 ) ;
419
439
done ( ) ;
420
440
} ) ;
421
- connection . get ( 'dogs' , 'fido' ) . create ( { age : 3 } ) ;
441
+ connection . get ( 'dogs' , 'fido' ) . on ( 'error' , done ) . create ( { age : 3 } ) ;
422
442
} ) ;
423
443
424
444
it ( 'changing a filtered property removes from a subscribed query' , function ( done ) {
425
445
var connection = this . backend . connect ( ) ;
426
446
async . parallel ( [
427
447
function ( cb ) {
428
- connection . get ( 'dogs' , 'fido' ) . create ( { age : 3 } , cb ) ;
448
+ connection . get ( 'dogs' , 'fido' ) . on ( 'error' , done ) . create ( { age : 3 } , cb ) ;
429
449
} ,
430
450
function ( cb ) {
431
- connection . get ( 'dogs' , 'spot' ) . create ( { age : 3 } , cb ) ;
451
+ connection . get ( 'dogs' , 'spot' ) . on ( 'error' , done ) . create ( { age : 3 } , cb ) ;
432
452
}
433
453
] , function ( err ) {
434
454
if ( err ) return done ( err ) ;
@@ -440,6 +460,7 @@ module.exports = function(options) {
440
460
expect ( util . pluck ( sorted , 'data' ) ) . eql ( [ { age : 3 } , { age : 3 } ] ) ;
441
461
connection . get ( 'dogs' , 'fido' ) . submitOp ( { p : [ 'age' ] , na : 2 } ) ;
442
462
} ) ;
463
+ query . on ( 'error' , done ) ;
443
464
query . on ( 'remove' , function ( docs , index ) {
444
465
expect ( util . pluck ( docs , 'id' ) ) . eql ( [ 'fido' ] ) ;
445
466
expect ( util . pluck ( docs , 'data' ) ) . eql ( [ { age : 5 } ] ) ;
@@ -456,10 +477,10 @@ module.exports = function(options) {
456
477
var connection = this . backend . connect ( ) ;
457
478
async . parallel ( [
458
479
function ( cb ) {
459
- connection . get ( 'dogs' , 'fido' ) . create ( { age : 3 } , cb ) ;
480
+ connection . get ( 'dogs' , 'fido' ) . on ( 'error' , done ) . create ( { age : 3 } , cb ) ;
460
481
} ,
461
482
function ( cb ) {
462
- connection . get ( 'dogs' , 'spot' ) . create ( { age : 5 } , cb ) ;
483
+ connection . get ( 'dogs' , 'spot' ) . on ( 'error' , done ) . create ( { age : 5 } , cb ) ;
463
484
}
464
485
] , function ( err ) {
465
486
if ( err ) return done ( err ) ;
@@ -471,6 +492,7 @@ module.exports = function(options) {
471
492
expect ( util . pluck ( sorted , 'data' ) ) . eql ( [ { age : 3 } ] ) ;
472
493
connection . get ( 'dogs' , 'spot' ) . submitOp ( { p : [ 'age' ] , na : - 2 } ) ;
473
494
} ) ;
495
+ query . on ( 'error' , done ) ;
474
496
query . on ( 'insert' , function ( docs , index ) {
475
497
expect ( util . pluck ( docs , 'id' ) ) . eql ( [ 'spot' ] ) ;
476
498
expect ( util . pluck ( docs , 'data' ) ) . eql ( [ { age : 3 } ] ) ;
@@ -488,10 +510,10 @@ module.exports = function(options) {
488
510
489
511
async . parallel ( [
490
512
function ( cb ) {
491
- connection . get ( 'dogs' , 'fido' ) . create ( { age : 3 } , cb ) ;
513
+ connection . get ( 'dogs' , 'fido' ) . on ( 'error' , done ) . create ( { age : 3 } , cb ) ;
492
514
} ,
493
515
function ( cb ) {
494
- connection . get ( 'dogs' , 'spot' ) . create ( { age : 5 } , cb ) ;
516
+ connection . get ( 'dogs' , 'spot' ) . on ( 'error' , done ) . create ( { age : 5 } , cb ) ;
495
517
}
496
518
] , function ( err ) {
497
519
if ( err ) return done ( err ) ;
@@ -506,7 +528,7 @@ module.exports = function(options) {
506
528
expect ( util . pluck ( results , 'data' ) ) . eql ( [ { age : 3 } , { age : 5 } ] ) ;
507
529
connection . get ( 'dogs' , 'spot' ) . submitOp ( { p : [ 'age' ] , na : - 3 } ) ;
508
530
} ) ;
509
-
531
+ query . on ( 'error' , done ) ;
510
532
query . on ( 'move' , function ( docs , from , to ) {
511
533
expect ( docs . length ) . eql ( 1 ) ;
512
534
expect ( from ) . a ( 'number' ) ;
0 commit comments