@@ -17,7 +17,6 @@ function ping(pingProtocol, resourceUrl, returnFormat) {
1717 let rpctext ;
1818 if ( null == resourceUrl ) {
1919 rpctext = xmlrpc . buildCall ( 'rssCloud.ping' , [ ] , 'xml' ) ;
20- console . log ( rpctext ) ;
2120 } else {
2221 rpctext = xmlrpc . buildCall ( 'rssCloud.ping' , [ resourceUrl ] , 'xml' ) ;
2322 }
@@ -91,7 +90,7 @@ for (const pingProtocol of ['XML-RPC', 'REST']) {
9190 mock . route ( 'GET' , feedPath , 200 , '<RSS Feed />' ) ;
9291 mock . route ( 'POST' , pingPath , 200 , 'Thanks for the update! :-)' ) ;
9392 mock . rpc ( notifyProcedure , rpcReturnSuccess ( true ) ) ;
94- mongodb . addSubscription ( resourceUrl , notifyProcedure , apiurl , protocol ) ;
93+ await mongodb . addSubscription ( resourceUrl , notifyProcedure , apiurl , protocol ) ;
9594
9695 let res = await ping ( pingProtocol , resourceUrl , returnFormat ) ;
9796
@@ -137,7 +136,7 @@ for (const pingProtocol of ['XML-RPC', 'REST']) {
137136 mock . route ( 'GET' , feedPath , 404 , 'Not Found' ) ;
138137 mock . route ( 'POST' , pingPath , 200 , 'Thanks for the update! :-)' ) ;
139138 mock . rpc ( notifyProcedure , rpcReturnSuccess ( true ) ) ;
140- mongodb . addSubscription ( resourceUrl , notifyProcedure , apiurl , protocol ) ;
139+ await mongodb . addSubscription ( resourceUrl , notifyProcedure , apiurl , protocol ) ;
141140
142141 let res = await ping ( pingProtocol , resourceUrl , returnFormat ) ;
143142
@@ -218,7 +217,7 @@ for (const pingProtocol of ['XML-RPC', 'REST']) {
218217 mock . route ( 'GET' , feedPath , 200 , '<RSS Feed />' ) ;
219218 mock . route ( 'POST' , pingPath , 200 , 'Thanks for the update! :-)' ) ;
220219 mock . rpc ( notifyProcedure , rpcReturnSuccess ( true ) ) ;
221- mongodb . addSubscription ( resourceUrl , notifyProcedure , apiurl , protocol ) ;
220+ await mongodb . addSubscription ( resourceUrl , notifyProcedure , apiurl , protocol ) ;
222221
223222 let res = await ping ( pingProtocol , resourceUrl , returnFormat ) ;
224223
@@ -257,6 +256,70 @@ for (const pingProtocol of ['XML-RPC', 'REST']) {
257256 }
258257 } ) ;
259258
259+ it ( `should accept a ping with slow subscribers` , async function ( ) {
260+ this . timeout ( 5000 ) ;
261+
262+ const feedPath = '/rss.xml' ,
263+ pingPath = '/feedupdated' ,
264+ resourceUrl = mock . serverUrl + feedPath ;
265+
266+ let apiurl = ( 'http-post' === protocol ? mock . serverUrl : mock . secureServerUrl ) + pingPath ,
267+ notifyProcedure = false ;
268+
269+ if ( 'xml-rpc' === protocol ) {
270+ apiurl = mock . serverUrl + '/RPC2' ;
271+ notifyProcedure = 'river.feedUpdated' ;
272+ }
273+
274+ function slowPostResponse ( req ) {
275+ return new Promise ( function ( resolve ) {
276+ setTimeout ( function ( ) {
277+ resolve ( 'Thanks for the update! :-)' ) ;
278+ } , 1000 ) ;
279+ } ) ;
280+ }
281+
282+ mock . route ( 'GET' , feedPath , 200 , '<RSS Feed />' ) ;
283+ if ( 'xml-rpc' === protocol ) {
284+ mock . rpc ( notifyProcedure , rpcReturnSuccess ( true ) ) ;
285+ await mongodb . addSubscription ( resourceUrl , notifyProcedure , apiurl , protocol ) ;
286+ } else {
287+ for ( let i = 0 ; i < 10 ; i ++ ) {
288+ mock . route ( 'POST' , pingPath + i , 200 , slowPostResponse ) ;
289+ await mongodb . addSubscription ( resourceUrl , notifyProcedure , apiurl + i , protocol ) ;
290+ }
291+ }
292+
293+ let res = await ping ( pingProtocol , resourceUrl , returnFormat ) ;
294+
295+ expect ( res ) . status ( 200 ) ;
296+
297+ if ( 'XML-RPC' === pingProtocol ) {
298+ expect ( res . text ) . xml . equal ( rpcReturnSuccess ( true ) ) ;
299+ } else {
300+ if ( 'JSON' === returnFormat ) {
301+ expect ( res . body ) . deep . equal ( { success : true , msg : 'Thanks for the ping.' } ) ;
302+ } else {
303+ expect ( res . text ) . xml . equal ( '<result success="true" msg="Thanks for the ping."/>' ) ;
304+ }
305+ }
306+
307+ expect ( mock . requests . GET ) . property ( feedPath ) . lengthOf ( 1 , `Missing GET ${ feedPath } ` ) ;
308+
309+ if ( 'xml-rpc' === protocol ) {
310+ expect ( mock . requests . RPC2 ) . property ( notifyProcedure ) . lengthOf ( 1 , `Missing XML-RPC call ${ notifyProcedure } ` ) ;
311+ expect ( mock . requests . RPC2 [ notifyProcedure ] [ 0 ] ) . property ( 'rpcBody' ) ;
312+ expect ( mock . requests . RPC2 [ notifyProcedure ] [ 0 ] . rpcBody . params [ 0 ] ) . equal ( resourceUrl ) ;
313+ } else {
314+ for ( let i = 0 ; i < 10 ; i ++ ) {
315+ expect ( mock . requests . POST ) . property ( pingPath + i ) . lengthOf ( 1 , `Missing POST ${ pingPath + i } ` ) ;
316+ expect ( mock . requests . POST [ pingPath + i ] [ 0 ] ) . property ( 'body' ) ;
317+ expect ( mock . requests . POST [ pingPath + i ] [ 0 ] . body ) . property ( 'url' ) ;
318+ expect ( mock . requests . POST [ pingPath + i ] [ 0 ] . body . url ) . equal ( resourceUrl ) ;
319+ }
320+ }
321+ } ) ;
322+
260323 } ) ;
261324
262325} // end for pingProtocol
0 commit comments