Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(cli): add check for intermediates matching aggregates in aws tests #3252

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/artillery/test/cloud-e2e/fargate/bom.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ const { test, before, beforeEach } = require('tap');
const { $ } = require('zx');
const fs = require('fs');
const { generateTmpReportPath, getTestTags } = require('../../helpers');
const { checkForNegativeValues } = require('../../helpers/expectations');
const {
checkForNegativeValues,
checkAggregateCounterSums
} = require('../../helpers/expectations');

const A9_PATH = process.env.A9_PATH || 'artillery';

Expand Down Expand Up @@ -59,4 +62,5 @@ test('Run mixed-hierarchy', async (t) => {
);

checkForNegativeValues(t, report);
checkAggregateCounterSums(t, report);
});
6 changes: 5 additions & 1 deletion packages/artillery/test/cloud-e2e/fargate/cw-adot.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ const {
getTestTags
} = require('../../helpers');
const { getTestId, getXRayTraces } = require('./fixtures/adot/helpers.js');
const { checkForNegativeValues } = require('../../helpers/expectations');
const {
checkForNegativeValues,
checkAggregateCounterSums
} = require('../../helpers/expectations');

const A9_PATH = process.env.A9_PATH || 'artillery';
// NOTE: This test reports to Artillery Dashboard to dogfood and improve visibility
Expand Down Expand Up @@ -46,6 +49,7 @@ test('traces succesfully arrive to cloudwatch', async (t) => {
const testId = getTestId(output.stdout);
const report = JSON.parse(fs.readFileSync(reportFilePath, 'utf8'));
checkForNegativeValues(t, report);
checkAggregateCounterSums(t, report);

let traceMap;
try {
Expand Down
6 changes: 5 additions & 1 deletion packages/artillery/test/cloud-e2e/fargate/dd-adot.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ const {
deleteFile,
getTestTags
} = require('../../helpers');
const { checkForNegativeValues } = require('../../helpers/expectations');
const {
checkForNegativeValues,
checkAggregateCounterSums
} = require('../../helpers/expectations');
const { getDatadogSpans, getTestId } = require('./fixtures/adot/helpers.js');

const A9_PATH = process.env.A9_PATH || 'artillery';
Expand Down Expand Up @@ -53,6 +56,7 @@ test('traces succesfully arrive to datadog', async (t) => {
const testId = getTestId(output.stdout);
const report = JSON.parse(fs.readFileSync(reportFilePath, 'utf8'));
checkForNegativeValues(t, report);
checkAggregateCounterSums(t, report);

let spanList;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ const { $ } = require('zx');
const chalk = require('chalk');
const fs = require('fs');
const { generateTmpReportPath, getTestTags } = require('../../helpers');
const { checkForNegativeValues } = require('../../helpers/expectations');
const {
checkForNegativeValues,
checkAggregateCounterSums
} = require('../../helpers/expectations');

const A9_PATH = process.env.A9_PATH || 'artillery';

Expand Down Expand Up @@ -40,6 +43,8 @@ test('Run uses ensure', async (t) => {
300,
'Should have 300 "200 OK" responses'
);

checkForNegativeValues(t, report);
checkAggregateCounterSums(t, report);
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ const { $ } = require('zx');
const chalk = require('chalk');
const fs = require('fs');
const { generateTmpReportPath, getTestTags } = require('../../helpers');
const { checkForNegativeValues } = require('../../helpers/expectations');
const {
checkForNegativeValues,
checkAggregateCounterSums
} = require('../../helpers/expectations');

const A9_PATH = process.env.A9_PATH || 'artillery';

Expand Down Expand Up @@ -41,7 +44,9 @@ test('CLI should exit with non-zero exit code when there are failed expectations
10,
'Should have 10 "200 OK" responses'
);

checkForNegativeValues(t, report);
checkAggregateCounterSums(t, report);
}
});

Expand Down
7 changes: 6 additions & 1 deletion packages/artillery/test/cloud-e2e/fargate/misc.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ const { $ } = require('zx');
const chalk = require('chalk');
const fs = require('fs');
const { generateTmpReportPath, getTestTags } = require('../../helpers');
const { checkForNegativeValues } = require('../../helpers/expectations');
const {
checkForNegativeValues,
checkAggregateCounterSums
} = require('../../helpers/expectations');

const A9_PATH = process.env.A9_PATH || 'artillery';

Expand Down Expand Up @@ -78,7 +81,9 @@ test('Kitchen Sink Test - multiple features together', async (t) => {
40,
'Should have 40 /pony "200 OK" responses'
);

checkForNegativeValues(t, report);
checkAggregateCounterSums(t, report);
});

test('Run lots-of-output', async (t) => {
Expand Down
9 changes: 8 additions & 1 deletion packages/artillery/test/cloud-e2e/fargate/processors.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ const { $ } = require('zx');
const fs = require('fs');
const path = require('path');
const { generateTmpReportPath, getTestTags } = require('../../helpers');
const { checkForNegativeValues } = require('../../helpers/expectations');
const {
checkForNegativeValues,
checkAggregateCounterSums
} = require('../../helpers/expectations');

const A9_PATH = process.env.A9_PATH || 'artillery';

Expand Down Expand Up @@ -37,7 +40,9 @@ test('Run with typescript processor and external package', async (t) => {
2,
'Should have emitted 2 errors'
);

checkForNegativeValues(t, report);
checkAggregateCounterSums(t, report);
});

test('Run a test with an ESM processor', async (t) => {
Expand All @@ -63,5 +68,7 @@ test('Run a test with an ESM processor', async (t) => {
10,
'Should have emitted 10 custom metrics from ts processor'
);

checkForNegativeValues(t, report);
checkAggregateCounterSums(t, report);
});
7 changes: 6 additions & 1 deletion packages/artillery/test/cloud-e2e/lambda/lambda-bom.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ const {
generateTmpReportPath,
getImageArchitecture
} = require('../../helpers');
const { checkForNegativeValues } = require('../../helpers/expectations');
const {
checkForNegativeValues,
checkAggregateCounterSums
} = require('../../helpers/expectations');

const tags = getTestTags(['type:acceptance']);

Expand Down Expand Up @@ -61,5 +64,7 @@ tap.test('Run mixed-hierarchy test in Lambda Container', async (t) => {
20,
'Should have 20 "200 OK" responses'
);

checkForNegativeValues(t, report);
checkAggregateCounterSums(t, report);
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ const {
generateTmpReportPath,
getImageArchitecture
} = require('../../helpers');
const { checkForNegativeValues } = require('../../helpers/expectations');
const {
checkForNegativeValues,
checkAggregateCounterSums
} = require('../../helpers/expectations');

const tags = getTestTags(['type:acceptance']);
const A9_PATH = process.env.A9_PATH || 'artillery';
Expand Down Expand Up @@ -44,5 +47,7 @@ tap.test('Run dotenv test in Lambda Container', async (t) => {
50,
'Should have custom counter for env variable fruit'
);

checkForNegativeValues(t, report);
checkAggregateCounterSums(t, report);
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ const {
getTestTags,
getImageArchitecture
} = require('../../helpers');
const { checkForNegativeValues } = require('../../helpers/expectations');
const {
checkForNegativeValues,
checkAggregateCounterSums
} = require('../../helpers/expectations');

//NOTE: all these tests report to Artillery Dashboard to dogfood and improve visibility
const tags = getTestTags(['type:acceptance']);
Expand Down Expand Up @@ -46,6 +49,8 @@ tap.test('Lambda Container run uses ensure', async (t) => {
300,
'Should have 300 "200 OK" responses'
);

checkForNegativeValues(t, report);
checkAggregateCounterSums(t, report);
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ const {
getTestTags,
getImageArchitecture
} = require('../../helpers');
const { checkForNegativeValues } = require('../../helpers/expectations');
const {
checkForNegativeValues,
checkAggregateCounterSums
} = require('../../helpers/expectations');

const tags = getTestTags(['type:acceptance']);
let reportFilePath;
Expand Down Expand Up @@ -54,7 +57,9 @@ tap.test(
10,
'Should have 10 "200 OK" responses'
);

checkForNegativeValues(t, report);
checkAggregateCounterSums(t, report);
}
}
);
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ const {
generateTmpReportPath,
getImageArchitecture
} = require('../../helpers');
const { checkForNegativeValues } = require('../../helpers/expectations');
const {
checkForNegativeValues,
checkAggregateCounterSums
} = require('../../helpers/expectations');

const tags = getTestTags(['type:acceptance']);

Expand Down Expand Up @@ -74,6 +77,8 @@ tap.test(
2,
'Should have emitted 2 errors'
);

checkForNegativeValues(t, report);
checkAggregateCounterSums(t, report);
}
);
31 changes: 30 additions & 1 deletion packages/artillery/test/helpers/expectations.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,35 @@ const checkForNegativeValues = (t, report) => {
}
};

const checkAggregateCounterSums = (t, report) => {
const aggregateCounters = report.aggregate?.counters;

if (!aggregateCounters || Object.keys(aggregateCounters).length === 0) {
t.fail('No aggregate counters found in the report');
}

let intermediateCounters = {};

for (const intermediate of report.intermediate) {
for (const key in intermediate.counters) {
if (intermediateCounters[key]) {
intermediateCounters[key] += intermediate.counters[key];
} else {
intermediateCounters[key] = intermediate.counters[key];
}
}
}

for (const key in aggregateCounters) {
if (aggregateCounters[key] !== intermediateCounters[key]) {
t.fail(
`Aggregate counter sum mismatch for ${key}. Aggregate ${aggregateCounters[key]} != Intermediate ${intermediateCounters[key]}`
);
}
}
};

module.exports = {
checkForNegativeValues
checkForNegativeValues,
checkAggregateCounterSums
};
Loading