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);
|
||||
});
|
||||
|
||||
_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) =>
|
||||
new Promise((resolve, reject) => {
|
||||
resolve(true);
|
||||
@@ -59,6 +100,12 @@ export default class ConnectorTest extends Connector{
|
||||
let updates;
|
||||
|
||||
switch (type) {
|
||||
case "fade-off":
|
||||
return this._fadeOffTest(false);
|
||||
|
||||
case "fade-in":
|
||||
return this._fadeOffTest(true);
|
||||
|
||||
case "hijack":
|
||||
updates = [
|
||||
{
|
||||
|
@@ -77,7 +77,9 @@ describe("Composition", function() {
|
||||
"uptimeMonitors",
|
||||
"pidFile",
|
||||
"multiProcess",
|
||||
"maxMessagesPerSecond"
|
||||
"maxMessagesPerSecond",
|
||||
"fadeOffSeconds",
|
||||
"checkFadeOffGroupsSeconds"
|
||||
]);
|
||||
expect(config.connectors[0]).to.have
|
||||
.property('class')
|
||||
@@ -177,7 +179,7 @@ describe("Composition", 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
|
||||
.containSubset({
|
||||
@@ -271,6 +273,16 @@ describe("Composition", function() {
|
||||
"ignore": false,
|
||||
"excludeMonitors" : [],
|
||||
"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);
|
||||
var expect = chai.expect;
|
||||
|
||||
var asyncTimeout = 20000;
|
||||
let asyncTimeout = 20000;
|
||||
global.EXTERNAL_VERSION_FOR_TEST = "0.0.1";
|
||||
global.EXTERNAL_CONFIG_FILE = "tests/config.test.yml";
|
||||
|
||||
|
||||
let visibilityDone = false;
|
||||
describe("Alerting", function () {
|
||||
var worker = require("../index");
|
||||
var pubSub = worker.pubSub;
|
||||
@@ -65,26 +65,29 @@ describe("Alerting", function () {
|
||||
|
||||
pubSub.subscribe("visibility", function (type, message) {
|
||||
|
||||
message = JSON.parse(JSON.stringify(message));
|
||||
if (!visibilityDone) {
|
||||
message = JSON.parse(JSON.stringify(message));
|
||||
|
||||
const id = message.id;
|
||||
const id = message.id;
|
||||
|
||||
expect(Object.keys(expectedData).includes(id)).to.equal(true);
|
||||
expect(expectedData[id] != null).to.equal(true);
|
||||
expect(Object.keys(expectedData).includes(id)).to.equal(true);
|
||||
expect(expectedData[id] != null).to.equal(true);
|
||||
|
||||
|
||||
expect(message).to
|
||||
.containSubset(expectedData[id]);
|
||||
expect(message).to
|
||||
.containSubset(expectedData[id]);
|
||||
|
||||
expect(message).to.contain
|
||||
.keys([
|
||||
"latest",
|
||||
"earliest"
|
||||
]);
|
||||
expect(message).to.contain
|
||||
.keys([
|
||||
"latest",
|
||||
"earliest"
|
||||
]);
|
||||
|
||||
delete expectedData[id];
|
||||
if (Object.keys(expectedData).length === 0){
|
||||
done();
|
||||
delete expectedData[id];
|
||||
if (Object.keys(expectedData).length === 0) {
|
||||
done();
|
||||
visibilityDone = true;
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
@@ -453,8 +456,6 @@ describe("Alerting", function () {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
it("asn monitoring reporting", function (done) {
|
||||
|
||||
pubSub.publish("test-type", "misconfiguration");
|
||||
@@ -489,11 +490,55 @@ describe("Alerting", function () {
|
||||
if (Object.keys(expectedData).length === 0){
|
||||
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);
|
||||
|
||||
});
|
||||
|
@@ -51,6 +51,8 @@ reports:
|
||||
|
||||
notificationIntervalSeconds: 1800 # Repeat the same alert (which keeps being triggered) after x seconds
|
||||
alertOnlyOnce: false
|
||||
fadeOffSeconds: 10
|
||||
checkFadeOffGroupsSeconds: 2
|
||||
|
||||
# The file containing the monitored prefixes. Please see monitored_prefixes_test.yml for an example
|
||||
# This is an array (use new lines and dashes!)
|
||||
|
@@ -84,6 +84,11 @@
|
||||
minLength: 2
|
||||
matchDescription: test description
|
||||
|
||||
165.24.225.0/24:
|
||||
description: test fade off
|
||||
asn: 15562
|
||||
ignoreMorespecifics: false
|
||||
|
||||
options:
|
||||
monitorASns:
|
||||
2914:
|
||||
|
Reference in New Issue
Block a user