File tree Expand file tree Collapse file tree 2 files changed +80
-2
lines changed Expand file tree Collapse file tree 2 files changed +80
-2
lines changed Original file line number Diff line number Diff line change @@ -295,11 +295,15 @@ ZongJi.prototype.stop = function () {
295
295
} ;
296
296
297
297
ZongJi . prototype . pause = function ( ) {
298
- this . connection . pause ( ) ;
298
+ if ( ! this . stopped ) {
299
+ this . connection . pause ( ) ;
300
+ }
299
301
} ;
300
302
301
303
ZongJi . prototype . resume = function ( ) {
302
- this . connection . resume ( ) ;
304
+ if ( ! this . stopped ) {
305
+ this . connection . resume ( ) ;
306
+ }
303
307
} ;
304
308
305
309
// It includes every events by default.
Original file line number Diff line number Diff line change @@ -440,3 +440,77 @@ tap.test('With many columns', (test) => {
440
440
) ;
441
441
} ) ;
442
442
} ) ;
443
+
444
+ tap . test ( 'Pause/Resume Binlog' , ( test ) => {
445
+ const TEST_TABLE = 'pause_resume_test_table' ;
446
+
447
+ test . test ( `prepare table ${ TEST_TABLE } ` , ( test ) => {
448
+ testDb . execute ( [ `DROP TABLE IF EXISTS ${ TEST_TABLE } ` , `CREATE TABLE ${ TEST_TABLE } (col INT UNSIGNED)` ] , ( err ) => {
449
+ if ( err ) {
450
+ return test . fail ( err ) ;
451
+ }
452
+
453
+ test . end ( ) ;
454
+ } ) ;
455
+ } ) ;
456
+
457
+ tap . test ( 'Pausing binlog stops events' , ( test ) => {
458
+ const events = [ ] ;
459
+ const zongji = new ZongJi ( settings . connection ) ;
460
+ test . teardown ( ( ) => zongji . stop ( ) ) ;
461
+
462
+ zongji . on ( 'ready' , ( ) => {
463
+ zongji . pause ( ) ;
464
+ paused = true ;
465
+ testDb . execute (
466
+ [
467
+ `INSERT INTO ${ TEST_TABLE } (col)
468
+ VALUES (14)`
469
+ ] ,
470
+ ( err ) => {
471
+ if ( err ) {
472
+ return test . fail ( err ) ;
473
+ }
474
+ }
475
+ ) ;
476
+ setTimeout ( ( ) => {
477
+ paused = false ;
478
+ zongji . resume ( ) ;
479
+ } , 20 ) ;
480
+ } ) ;
481
+
482
+ zongji . start ( {
483
+ startAtEnd : true ,
484
+ serverId : testDb . serverId ( ) ,
485
+ includeEvents : [ 'tablemap' , 'writerows' ]
486
+ } ) ;
487
+
488
+ let paused = false ;
489
+ zongji . on ( 'binlog' , ( evt ) => {
490
+ if ( paused ) {
491
+ // We don't expect any events while paused
492
+ test . fail ( ) ;
493
+ return ;
494
+ }
495
+
496
+ events . push ( evt ) ;
497
+ if ( events . length == 2 ) {
498
+ expectEvents (
499
+ test ,
500
+ events ,
501
+ [
502
+ tableMapEvent ( TEST_TABLE ) ,
503
+ {
504
+ _type : 'WriteRows' ,
505
+ _checkTableMap : checkTableMatches ( TEST_TABLE ) ,
506
+ rows : [ { col : 14 } ]
507
+ }
508
+ ] ,
509
+ 1 ,
510
+ ( ) => test . end ( )
511
+ ) ;
512
+ }
513
+ } ) ;
514
+ } ) ;
515
+ test . end ( ) ;
516
+ } ) ;
You can’t perform that action at this time.
0 commit comments