Skip to content

Commit a3d780a

Browse files
committed
Do not notify subscriptions with excessive errors
1 parent 05f53ec commit a3d780a

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

services/notify-subscribers.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"use strict";
33

44
const appMessages = require('./app-messages'),
5+
config = require('../config'),
56
logEvent = require('./log-event'),
67
moment = require('moment'),
78
mongodb = require('./mongodb'),
@@ -68,6 +69,10 @@
6869
return false
6970
}
7071

72+
if (subscription.ctConsecutiveErrors >= config.maxConsecutiveErrors) {
73+
return false;
74+
}
75+
7176
return true;
7277
}
7378

test/ping.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,49 @@ for (const pingProtocol of ['XML-RPC', 'REST']) {
365365
}
366366
});
367367

368+
it(`should not notify subscribers with excessive errors`, async function () {
369+
const feedPath = '/rss.xml',
370+
pingPath = '/feedupdated',
371+
resourceUrl = mock.serverUrl + feedPath;
372+
373+
let apiurl = ('http-post' === protocol ? mock.serverUrl : mock.secureServerUrl) + pingPath,
374+
notifyProcedure = false;
375+
376+
if ('xml-rpc' === protocol) {
377+
apiurl = mock.serverUrl + '/RPC2';
378+
notifyProcedure = 'river.feedUpdated';
379+
}
380+
381+
mock.route('GET', feedPath, 200, '<RSS Feed />');
382+
mock.route('POST', pingPath, 200, 'Thanks for the update! :-)');
383+
mock.rpc(notifyProcedure, rpcReturnSuccess(true));
384+
const subscription = await mongodb.addSubscription(resourceUrl, notifyProcedure, apiurl, protocol);
385+
subscription.ctConsecutiveErrors = config.maxConsecutiveErrors;
386+
await mongodb.updateSubscription(resourceUrl, subscription);
387+
388+
let res = await ping(pingProtocol, resourceUrl, returnFormat);
389+
390+
expect(res).status(200);
391+
392+
if ('XML-RPC' === pingProtocol) {
393+
expect(res.text).xml.equal(rpcReturnSuccess(true));
394+
} else {
395+
if ('JSON' === returnFormat) {
396+
expect(res.body).deep.equal({ success: true, msg: 'Thanks for the ping.' });
397+
} else {
398+
expect(res.text).xml.equal('<result success="true" msg="Thanks for the ping."/>');
399+
}
400+
}
401+
402+
expect(mock.requests.GET).property(feedPath).lengthOf(1, `Missing GET ${feedPath}`);
403+
404+
if ('xml-rpc' === protocol) {
405+
expect(mock.requests.RPC2).property(notifyProcedure).lengthOf(0, `Missing XML-RPC call ${notifyProcedure}`);
406+
} else {
407+
expect(mock.requests.POST).property(pingPath).lengthOf(0, `Missing POST ${pingPath}`);
408+
}
409+
});
410+
368411
});
369412

370413
} // end for pingProtocol

0 commit comments

Comments
 (0)