@@ -650,10 +650,12 @@ describe('Subscriber', function() {
650650 } ) ;
651651
652652 it ( 'should send any pending nacks' , function ( ) {
653- const fakeAckIds = ( subscriber . inventory_ . nack = [ 'ghi' , 'jkl' ] ) ;
653+ const fakeAckIds = [ 'ghi' , 'jkl' ] ;
654+
655+ subscriber . inventory_ . nack = fakeAckIds . map ( ackId => [ ackId , 0 ] ) ;
654656
655657 subscriber . modifyAckDeadline_ = function ( ackIds , deadline ) {
656- assert . strictEqual ( ackIds , fakeAckIds ) ;
658+ assert . deepStrictEqual ( ackIds , fakeAckIds ) ;
657659 assert . strictEqual ( deadline , 0 ) ;
658660 return Promise . resolve ( ) ;
659661 } ;
@@ -662,6 +664,22 @@ describe('Subscriber', function() {
662664 assert . strictEqual ( subscriber . inventory_ . nack . length , 0 ) ;
663665 } ) ;
664666 } ) ;
667+
668+ it ( 'should send any pending delayed nacks' , function ( ) {
669+ const fakeAckIds = [ 'ghi' , 'jkl' ] ;
670+
671+ subscriber . inventory_ . nack = fakeAckIds . map ( ackId => [ ackId , 1 ] ) ;
672+
673+ subscriber . modifyAckDeadline_ = function ( ackIds , deadline ) {
674+ assert . deepStrictEqual ( ackIds , fakeAckIds ) ;
675+ assert . strictEqual ( deadline , 1 ) ;
676+ return Promise . resolve ( ) ;
677+ } ;
678+
679+ return subscriber . flushQueues_ ( ) . then ( function ( ) {
680+ assert . strictEqual ( subscriber . inventory_ . nack . length , 0 ) ;
681+ } ) ;
682+ } ) ;
665683 } ) ;
666684
667685 describe ( 'isConnected_' , function ( ) {
@@ -1045,6 +1063,18 @@ describe('Subscriber', function() {
10451063
10461064 subscriber . nack_ ( MESSAGE ) ;
10471065 } ) ;
1066+
1067+ it ( 'should use the delay if passed' , function ( done ) {
1068+ subscriber . modifyAckDeadline_ = function ( ackId , deadline , connId ) {
1069+ assert . strictEqual ( ackId , MESSAGE . ackId ) ;
1070+ assert . strictEqual ( deadline , 1 ) ;
1071+ assert . strictEqual ( connId , MESSAGE . connectionId ) ;
1072+ setImmediate ( done ) ;
1073+ return Promise . resolve ( ) ;
1074+ } ;
1075+
1076+ subscriber . nack_ ( MESSAGE , 1 ) ;
1077+ } ) ;
10481078 } ) ;
10491079
10501080 describe ( 'without connection' , function ( ) {
@@ -1056,7 +1086,10 @@ describe('Subscriber', function() {
10561086
10571087 it ( 'should queue the message to be nacked if no conn' , function ( done ) {
10581088 subscriber . setFlushTimeout_ = function ( ) {
1059- assert ( subscriber . inventory_ . nack . indexOf ( MESSAGE . ackId ) > - 1 ) ;
1089+ assert . deepStrictEqual (
1090+ subscriber . inventory_ . nack ,
1091+ [ [ MESSAGE . ackId , 0 ] ]
1092+ ) ;
10601093 setImmediate ( done ) ;
10611094 return Promise . resolve ( ) ;
10621095 } ;
@@ -1072,6 +1105,20 @@ describe('Subscriber', function() {
10721105
10731106 subscriber . nack_ ( MESSAGE ) ;
10741107 } ) ;
1108+
1109+ it ( 'should use the delay if passed when queueing' , function ( done ) {
1110+ subscriber . setFlushTimeout_ = function ( ) {
1111+ assert (
1112+ subscriber . inventory_ . nack . findIndex ( element => {
1113+ return element [ 0 ] === MESSAGE . ackId && element [ 1 ] === 1 ;
1114+ } ) > - 1
1115+ ) ;
1116+ setImmediate ( done ) ;
1117+ return Promise . resolve ( ) ;
1118+ } ;
1119+
1120+ subscriber . nack_ ( MESSAGE , 1 ) ;
1121+ } ) ;
10751122 } ) ;
10761123 } ) ;
10771124
0 commit comments