mirror of
https://github.com/nttgin/BGPalerter.git
synced 2024-05-19 06:50:08 +00:00
added test coverage for fade off feature
This commit is contained in:
@@ -50,6 +50,47 @@ export default class ConnectorTest extends Connector{
|
|||||||
resolve(true);
|
resolve(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
_fadeOffTest = (fade) => {
|
||||||
|
const updates = [
|
||||||
|
{
|
||||||
|
data: {
|
||||||
|
withdrawals: ["165.24.225.0/24"],
|
||||||
|
peer: "124.0.0.1"
|
||||||
|
},
|
||||||
|
type: "ris_message"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
data: {
|
||||||
|
withdrawals: ["165.24.225.0/24"],
|
||||||
|
peer: "124.0.0.2"
|
||||||
|
},
|
||||||
|
type: "ris_message"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
data: {
|
||||||
|
withdrawals: ["165.24.225.0/24"],
|
||||||
|
peer: "124.0.0.3"
|
||||||
|
},
|
||||||
|
type: "ris_message"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
data: {
|
||||||
|
withdrawals: ["165.24.225.0/24"],
|
||||||
|
peer: "124.0.0.4"
|
||||||
|
},
|
||||||
|
type: "ris_message"
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
this._message(updates[0]);
|
||||||
|
this._message(updates[1]);
|
||||||
|
this._message(updates[2]);
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
this._message(updates[3]);
|
||||||
|
}, (this.config.fadeOffSeconds + ((fade) ? -4 : 4)) * 1000); // depending on "fade" it goes in our out of the fading period
|
||||||
|
};
|
||||||
|
|
||||||
subscribe = (params) =>
|
subscribe = (params) =>
|
||||||
new Promise((resolve, reject) => {
|
new Promise((resolve, reject) => {
|
||||||
resolve(true);
|
resolve(true);
|
||||||
@@ -59,6 +100,12 @@ export default class ConnectorTest extends Connector{
|
|||||||
let updates;
|
let updates;
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
|
case "fade-off":
|
||||||
|
return this._fadeOffTest(false);
|
||||||
|
|
||||||
|
case "fade-in":
|
||||||
|
return this._fadeOffTest(true);
|
||||||
|
|
||||||
case "hijack":
|
case "hijack":
|
||||||
updates = [
|
updates = [
|
||||||
{
|
{
|
||||||
|
@@ -77,7 +77,9 @@ describe("Composition", function() {
|
|||||||
"uptimeMonitors",
|
"uptimeMonitors",
|
||||||
"pidFile",
|
"pidFile",
|
||||||
"multiProcess",
|
"multiProcess",
|
||||||
"maxMessagesPerSecond"
|
"maxMessagesPerSecond",
|
||||||
|
"fadeOffSeconds",
|
||||||
|
"checkFadeOffGroupsSeconds"
|
||||||
]);
|
]);
|
||||||
expect(config.connectors[0]).to.have
|
expect(config.connectors[0]).to.have
|
||||||
.property('class')
|
.property('class')
|
||||||
@@ -177,7 +179,7 @@ describe("Composition", function() {
|
|||||||
|
|
||||||
it("loading prefixes", function () {
|
it("loading prefixes", function () {
|
||||||
|
|
||||||
expect(input.prefixes.length).to.equal(12);
|
expect(input.prefixes.length).to.equal(13);
|
||||||
|
|
||||||
expect(JSON.parse(JSON.stringify(input))).to
|
expect(JSON.parse(JSON.stringify(input))).to
|
||||||
.containSubset({
|
.containSubset({
|
||||||
@@ -271,6 +273,16 @@ describe("Composition", function() {
|
|||||||
"ignore": false,
|
"ignore": false,
|
||||||
"excludeMonitors" : [],
|
"excludeMonitors" : [],
|
||||||
"includeMonitors": ["prefix-detection"]
|
"includeMonitors": ["prefix-detection"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"asn": [15562],
|
||||||
|
"description": "test fade off",
|
||||||
|
"ignoreMorespecifics": false,
|
||||||
|
"prefix": "165.24.225.0/24",
|
||||||
|
"group": "default",
|
||||||
|
"ignore": false,
|
||||||
|
"excludeMonitors" : [],
|
||||||
|
"includeMonitors": []
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
@@ -35,11 +35,11 @@ var chaiSubset = require('chai-subset');
|
|||||||
chai.use(chaiSubset);
|
chai.use(chaiSubset);
|
||||||
var expect = chai.expect;
|
var expect = chai.expect;
|
||||||
|
|
||||||
var asyncTimeout = 20000;
|
let asyncTimeout = 20000;
|
||||||
global.EXTERNAL_VERSION_FOR_TEST = "0.0.1";
|
global.EXTERNAL_VERSION_FOR_TEST = "0.0.1";
|
||||||
global.EXTERNAL_CONFIG_FILE = "tests/config.test.yml";
|
global.EXTERNAL_CONFIG_FILE = "tests/config.test.yml";
|
||||||
|
|
||||||
|
let visibilityDone = false;
|
||||||
describe("Alerting", function () {
|
describe("Alerting", function () {
|
||||||
var worker = require("../index");
|
var worker = require("../index");
|
||||||
var pubSub = worker.pubSub;
|
var pubSub = worker.pubSub;
|
||||||
@@ -65,6 +65,7 @@ describe("Alerting", function () {
|
|||||||
|
|
||||||
pubSub.subscribe("visibility", function (type, message) {
|
pubSub.subscribe("visibility", function (type, message) {
|
||||||
|
|
||||||
|
if (!visibilityDone) {
|
||||||
message = JSON.parse(JSON.stringify(message));
|
message = JSON.parse(JSON.stringify(message));
|
||||||
|
|
||||||
const id = message.id;
|
const id = message.id;
|
||||||
@@ -83,8 +84,10 @@ describe("Alerting", function () {
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
delete expectedData[id];
|
delete expectedData[id];
|
||||||
if (Object.keys(expectedData).length === 0){
|
if (Object.keys(expectedData).length === 0) {
|
||||||
done();
|
done();
|
||||||
|
visibilityDone = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
@@ -453,8 +456,6 @@ describe("Alerting", function () {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
it("asn monitoring reporting", function (done) {
|
it("asn monitoring reporting", function (done) {
|
||||||
|
|
||||||
pubSub.publish("test-type", "misconfiguration");
|
pubSub.publish("test-type", "misconfiguration");
|
||||||
@@ -489,11 +490,55 @@ describe("Alerting", function () {
|
|||||||
if (Object.keys(expectedData).length === 0){
|
if (Object.keys(expectedData).length === 0){
|
||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
}).timeout(asyncTimeout);
|
||||||
|
|
||||||
|
|
||||||
|
it("fading alerting", function (done) {
|
||||||
|
|
||||||
|
pubSub.publish("test-type", "fade-off");
|
||||||
|
|
||||||
|
let notReceived = true;
|
||||||
|
// const expectedData = {
|
||||||
|
// "165.24.225.0/24": {
|
||||||
|
// id: '165.24.225.0/24',
|
||||||
|
// truncated: false,
|
||||||
|
// origin: 'withdrawal-detection',
|
||||||
|
// affected: 15562,
|
||||||
|
// message: 'The prefix 165.24.225.0/24 (test fade in) has been withdrawn. It is no longer visible from 4 peers.',
|
||||||
|
// data: [
|
||||||
|
// {
|
||||||
|
// affected: 15562,
|
||||||
|
// extra: {}
|
||||||
|
// },
|
||||||
|
// {
|
||||||
|
// affected: 15562,
|
||||||
|
// extra: {}
|
||||||
|
// },
|
||||||
|
// {
|
||||||
|
// affected: 15562,
|
||||||
|
// extra: {}
|
||||||
|
// },
|
||||||
|
// {
|
||||||
|
// affected: 15562,
|
||||||
|
// extra: {}
|
||||||
|
// }
|
||||||
|
// ]
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// };
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
if (notReceived){
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
}, 15000);
|
||||||
|
|
||||||
|
pubSub.subscribe("visibility", function (type, message) {
|
||||||
|
notReceived = false;
|
||||||
|
});
|
||||||
|
|
||||||
}).timeout(asyncTimeout);
|
}).timeout(asyncTimeout);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@@ -51,6 +51,8 @@ reports:
|
|||||||
|
|
||||||
notificationIntervalSeconds: 1800 # Repeat the same alert (which keeps being triggered) after x seconds
|
notificationIntervalSeconds: 1800 # Repeat the same alert (which keeps being triggered) after x seconds
|
||||||
alertOnlyOnce: false
|
alertOnlyOnce: false
|
||||||
|
fadeOffSeconds: 10
|
||||||
|
checkFadeOffGroupsSeconds: 2
|
||||||
|
|
||||||
# The file containing the monitored prefixes. Please see monitored_prefixes_test.yml for an example
|
# The file containing the monitored prefixes. Please see monitored_prefixes_test.yml for an example
|
||||||
# This is an array (use new lines and dashes!)
|
# This is an array (use new lines and dashes!)
|
||||||
|
@@ -84,6 +84,11 @@
|
|||||||
minLength: 2
|
minLength: 2
|
||||||
matchDescription: test description
|
matchDescription: test description
|
||||||
|
|
||||||
|
165.24.225.0/24:
|
||||||
|
description: test fade off
|
||||||
|
asn: 15562
|
||||||
|
ignoreMorespecifics: false
|
||||||
|
|
||||||
options:
|
options:
|
||||||
monitorASns:
|
monitorASns:
|
||||||
2914:
|
2914:
|
||||||
|
Reference in New Issue
Block a user