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

fix: write Playwright traces to a unique directory #2717

Merged
merged 3 commits into from
May 9, 2024
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
4 changes: 3 additions & 1 deletion packages/artillery-engine-playwright/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ class PlaywrightEngine {
1000 * 60 * (Math.ceil(Math.random() * 5) + 5);

this.tracePaths = [];
this.traceOutputDir = process.env.PLAYWRIGHT_TRACING_OUTPUT_DIR || '/tmp';
this.traceOutputDir =
process.env.PLAYWRIGHT_TRACING_OUTPUT_DIR ||
`/tmp/${global.artillery.testRunId}`;

return this;
}
Expand Down
4 changes: 4 additions & 0 deletions packages/artillery/lib/cmds/run-fargate.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const { supportedRegions } = require('../platform/aws-ecs/legacy/util');
const PlatformECS = require('../platform/aws-ecs/ecs');
const { ECS_WORKER_ROLE_NAME } = require('../platform/aws/constants');
const { Plugin: CloudPlugin } = require('../platform/cloud/cloud');
const generateId = require('../util/generate-id');
const dotenv = require('dotenv');
const path = require('path');
const fs = require('fs');
Expand All @@ -35,6 +36,9 @@ class RunCommand extends Command {
dotenv.config({ path: dotEnvPath });
}

const testRunId = process.env.ARTILLERY_TEST_RUN_ID || generateId('t');
global.artillery.testRunId = testRunId;

const cloud = new CloudPlugin(null, null, { flags });
if (cloud.enabled) {
try {
Expand Down
8 changes: 4 additions & 4 deletions packages/artillery/lib/cmds/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ RunCommand.runCommandImplementation = async function (flags, argv, args) {
checkDirExists(flags.output);
}

const testRunId = process.env.ARTILLERY_TEST_RUN_ID || generateId('t');
console.log('Test run id:', testRunId);
global.artillery.testRunId = testRunId;

try {
cloud = new CloudPlugin(null, null, { flags });
global.artillery.cloudEnabled = cloud.enabled;
Expand Down Expand Up @@ -172,10 +176,6 @@ RunCommand.runCommandImplementation = async function (flags, argv, args) {
}
}

const testRunId = process.env.ARTILLERY_TEST_RUN_ID || generateId('t');
console.log('Test run id:', testRunId);
global.artillery.testRunId = testRunId;

const script = await prepareTestExecutionPlan(inputFiles, flags, args);

var runnerOpts = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,9 +289,7 @@ async function tryRunCluster(scriptPath, options, artilleryReporter) {

context.extraSecrets = options.secret || [];

const testRunId = process.env.ARTILLERY_TEST_RUN_ID || generateId('t');
context.testId = testRunId;
global.artillery.testRunId = testRunId;
context.testId = global.artillery.testRunId;

if (context.namedTest) {
context.s3Prefix = options.bundle;
Expand Down
31 changes: 19 additions & 12 deletions packages/artillery/lib/platform/cloud/cloud.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,22 +236,29 @@ class ArtilleryCloudPlugin {
email: body.email
};

const watcher = chokidar.watch(
process.env.PLAYWRIGHT_TRACING_OUTPUT_DIR || '/tmp',
{
ignored: /(^|[\/\\])\../, // ignore dotfiles
persistent: true,
ignorePermissionErrors: true,
ignoreInitial: true
const outputDir =
process.env.PLAYWRIGHT_TRACING_OUTPUT_DIR ||
`/tmp/${global.artillery.testRunId}/`;

try {
fs.mkdirSync(outputDir, { recursive: true });
} catch (_err) {}

const watcher = chokidar.watch(outputDir, {
ignored: /(^|[\/\\])\../, // ignore dotfiles
persistent: true,
ignorePermissionErrors: true,
ignoreInitial: true,
awaitWriteFinish: {
stabilityThreshold: 2000,
pollInterval: 500
}
);
});

watcher.on('add', (fp) => {
if (path.basename(fp).startsWith('trace-') && fp.endsWith('.zip')) {
setTimeout(() => {
this.uploading++;
this._uploadAsset(fp);
}, 5 * 1000);
this.uploading++;
this._uploadAsset(fp);
}
});
}
Expand Down
Loading