Skip to content

Commit

Permalink
test(cli): fix windows tests issues (#3288)
Browse files Browse the repository at this point in the history
  • Loading branch information
bernardobridge authored Jul 25, 2024
1 parent 43068a4 commit c69bc00
Show file tree
Hide file tree
Showing 13 changed files with 128 additions and 522 deletions.
510 changes: 36 additions & 474 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/artillery-engine-playwright/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@
},
"devDependencies": {
"tap": "^19.0.2",
"zx": "^4.3.0"
"zx": "^8.1.4"
}
}
2 changes: 1 addition & 1 deletion packages/artillery-plugin-ensure/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@
},
"devDependencies": {
"tap": "^19.0.2",
"zx": "^4.3.0"
"zx": "^8.1.4"
}
}
4 changes: 2 additions & 2 deletions packages/artillery-plugin-memory-inspector/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Inspect the memory of processes running together with your load tests!",
"main": "index.js",
"scripts": {
"test": "tap ./test/*.spec.mjs --timeout 300"
"test": "tap ./test/*.spec.js --timeout 300"
},
"tap": {
"disable-coverage": true,
Expand All @@ -23,6 +23,6 @@
"devDependencies": {
"portfinder": "^1.0.32",
"tap": "^19.0.2",
"zx": "^7.2.3"
"zx": "^8.1.4"
}
}
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
import fs from 'fs';
import { startTestServer } from './util.mjs';
import { test, afterEach } from 'tap';
import { $ } from 'zx';
const fs = require('fs');
const { startTestServer } = require('./util.js');
const { test, afterEach } = require('tap');
const { $ } = require('zx');

let childProcess;

afterEach(async () => {
//cleanup output file after each test
fs.unlinkSync('./test/output.json');
childProcess.kill()
childProcess.kill();
});

test('cpu and memory metrics display in the aggregate report with the correct name and unit', async (t) => {
//Arrange: Test Server and Plugin overrides
const testServer = await startTestServer();
childProcess = testServer.childProcess
childProcess = testServer.childProcess;

const override = JSON.stringify({
config: {
plugins: {
'memory-inspector': [{ pid: testServer.currentPid, name: 'express-example', unit: 'kb' }]
'memory-inspector': [
{ pid: testServer.currentPid, name: 'express-example', unit: 'kb' }
]
}
}
});
Expand Down Expand Up @@ -66,15 +68,20 @@ test('cpu and memory metrics display in the aggregate report with the correct na
"Aggregate Histograms doesn't have Memory metric"
);

//assert that kb unit is used
for (const [metric, value] of Object.entries(report.aggregate.summaries['express-example.memory'])) {
if (metric == 'count') {
continue;
}

const lengthOfValue = Math.round(value).toString().length;
t.ok(lengthOfValue > 3 && lengthOfValue <= 6, `Length of value ${value} should be in KB (more than mb unit, less than byte unit)`)
//assert that kb unit is used
for (const [metric, value] of Object.entries(
report.aggregate.summaries['express-example.memory']
)) {
if (metric == 'count') {
continue;
}

const lengthOfValue = Math.round(value).toString().length;
t.ok(
lengthOfValue > 3 && lengthOfValue <= 6,
`Length of value ${value} should be in KB (more than mb unit, less than byte unit)`
);
}
});

test('cpu and memory metrics display in the aggregate report with a default name and unit when no name is given', async (t) => {
Expand Down Expand Up @@ -124,13 +131,18 @@ test('cpu and memory metrics display in the aggregate report with a default name
);

//assert that mb unit is used by default
for (const [metric, value] of Object.entries(report.aggregate.summaries[`process_${testServer.currentPid}.memory`])) {
for (const [metric, value] of Object.entries(
report.aggregate.summaries[`process_${testServer.currentPid}.memory`]
)) {
if (metric == 'count') {
continue;
}

const lengthOfValue = Math.round(value).toString().length;
t.ok(lengthOfValue <= 3, `Length of value ${value} in MB should be less than 4`)
t.ok(
lengthOfValue <= 3,
`Length of value ${value} in MB should be less than 4`
);
}
});

Expand All @@ -142,7 +154,9 @@ test('cpu and memory metrics also display in the aggregate report for artillery
const override = JSON.stringify({
config: {
plugins: {
'memory-inspector': [{ pid: testServer.currentPid, name: 'express-example' }]
'memory-inspector': [
{ pid: testServer.currentPid, name: 'express-example' }
]
}
}
});
Expand Down Expand Up @@ -223,13 +237,18 @@ test('cpu and memory metrics also display in the aggregate report for artillery
"Aggregate Histograms doesn't have Artillery Heap Total metric"
);

//assert that mb unit is used by default
for (const [metric, value] of Object.entries(report.aggregate.summaries['artillery_internal.memory'])) {
//assert that mb unit is used by default
for (const [metric, value] of Object.entries(
report.aggregate.summaries['artillery_internal.memory']
)) {
if (metric == 'count') {
continue;
}

const lengthOfValue = Math.round(value).toString().length;
t.ok(lengthOfValue <= 3, `Length of value ${value} in MB should be less than 4`)
t.ok(
lengthOfValue <= 3,
`Length of value ${value} in MB should be less than 4`
);
}
});
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import http from 'http';
const http = require('http');
const port = process.env.TEST_PORT || 4444;

// Array that will keep growing, causing a memory leak
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import portfinder from 'portfinder';
import { spawn } from 'child_process';
const portfinder = require('portfinder');
const { spawn } = require('child_process');

export const startTestServer = async () => {
const startTestServer = async () => {
const port = await portfinder.getPortPromise({
port: 4444,
stopPort: 4600
});

const childProcess = spawn(`node`, ['./test/server/server.mjs'], {
const childProcess = spawn('node', ['./test/server/server.js'], {
env: {
...process.env,
TEST_PORT: `${port}`
Expand All @@ -21,3 +21,7 @@ export const startTestServer = async () => {
childProcess
};
};

module.exports = {
startTestServer
};
2 changes: 1 addition & 1 deletion packages/artillery-plugin-metrics-by-endpoint/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@
},
"devDependencies": {
"tap": "^19.0.2",
"zx": "^4.3.0"
"zx": "^8.1.4"
}
}
2 changes: 1 addition & 1 deletion packages/artillery-plugin-publish-metrics/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@
"devDependencies": {
"shelljs": "^0.8.4",
"tap": "^19.0.2",
"zx": "^4.3.0"
"zx": "^8.1.4"
}
}
2 changes: 1 addition & 1 deletion packages/artillery/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,6 @@
"rewiremock": "^3.14.3",
"sinon": "^4.5.0",
"tap": "^19.0.2",
"zx": "^4.2.0"
"zx": "^8.1.4"
}
}
32 changes: 20 additions & 12 deletions packages/artillery/test/cli/custom-plugin.test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
const { test, beforeEach, before, afterEach } = require('tap');
const http = require('http');
const { $ } = require('zx');
const http = require('http');
const path = require('path');
const { toCorrectPath } = require('../helpers');

const A9 = process.env.A9 || path.join(__dirname, '../../bin/run');
const A9 = toCorrectPath(
process.env.A9 || path.join(__dirname, '../../bin/run')
);

function createServer() {
return http.createServer((req, res) => {
Expand Down Expand Up @@ -31,9 +34,11 @@ beforeEach(async () => {
config: {
phases: [{ duration: 2, arrivalRate: 2 }],
target: `http://localhost:${server.address().port}`,
processor: path.join(
__dirname,
'../scripts/scenario-with-custom-plugin/processor.js'
processor: toCorrectPath(
path.join(
__dirname,
'../scripts/scenario-with-custom-plugin/processor.js'
)
),
plugins: {
httphooks: {}
Expand All @@ -47,13 +52,16 @@ afterEach(async () => {
});

test('plugins can attach functions to processor object', async (t) => {
const output = await $`ARTILLERY_PLUGIN_PATH=${path.join(
__dirname,
'../plugins'
)} ${A9} run --quiet --overrides ${overrides} ${path.join(
__dirname,
'../scripts/scenario-with-custom-plugin/custom-plugin.yml'
)}`;
const pluginPath = toCorrectPath(path.join(__dirname, '../plugins'));
const scenarioPath = toCorrectPath(
path.join(
__dirname,
'../scripts/scenario-with-custom-plugin/custom-plugin.yml'
)
);

const output =
await $`ARTILLERY_PLUGIN_PATH=${pluginPath} ${A9} run --quiet --overrides ${overrides} ${scenarioPath}`;

t.match(output, /afterResponse hook/, 'plugin should have been called');
});
12 changes: 9 additions & 3 deletions packages/artillery/test/cloud-e2e/fargate/bom.test.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
const { test, before, beforeEach } = require('tap');
const { $ } = require('zx');
const fs = require('fs');
const { generateTmpReportPath, getTestTags } = require('../../helpers');
const {
generateTmpReportPath,
getTestTags,
toCorrectPath
} = require('../../helpers');
const {
checkForNegativeValues,
checkAggregateCounterSums
} = require('../../helpers/expectations');

const A9_PATH = process.env.A9_PATH || 'artillery';
const A9_PATH = toCorrectPath(process.env.A9_PATH || 'artillery');

before(async () => {
await $`${A9_PATH} -V`;
Expand All @@ -23,7 +27,9 @@ beforeEach(async (t) => {
});

test('Run simple-bom', async (t) => {
const scenarioPath = `${__dirname}/fixtures/simple-bom/simple-bom.yml`;
const scenarioPath = toCorrectPath(
`${__dirname}/fixtures/simple-bom/simple-bom.yml`
);

const output =
await $`${A9_PATH} run-fargate ${scenarioPath} --environment test --region eu-west-1 --count 51 --tags ${baseTags} --record`;
Expand Down
7 changes: 7 additions & 0 deletions packages/artillery/test/helpers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,19 @@ const getImageArchitecture = () => {
return process.env.HAS_ARM64_BUILD === 'true' ? 'arm64' : 'x86_64';
};

const toCorrectPath = (originalPath) => {
return process.platform === 'win32'
? originalPath.split(path.sep).join(path.posix.sep)
: originalPath;
};

module.exports = {
execute,
deleteFile,
getRootPath,
returnTmpPath,
generateTmpReportPath,
getTestTags,
toCorrectPath,
getImageArchitecture
};

0 comments on commit c69bc00

Please sign in to comment.