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

[WIP] Added initial support for aggregate runs during worker runs #3

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
59 changes: 47 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const RPClient = require('reportportal-client');
const fs = require('fs');
const path = require('path');
const debug = require('debug')('codeceptjs:reportportal');
const { isMainThread } = require('worker_threads');
const { event, recorder, output, container } = codeceptjs;

const helpers = container.helpers();
Expand Down Expand Up @@ -53,18 +54,27 @@ module.exports = (config) => {
let launchStatus = rp_PASSED;
let currentMetaSteps = [];

// only for codeceptjs 3.0+
event.dispatcher.on(event.workers.before, () => {
recorder.startUnlessRunning();
recorder.add(async () => {
launchObj = startLaunch();
const { id } = await launchObj.promise;
process.env.RP_LAUNCH_ID = id;
debug(`Setting env variable ${process.env.RP_LAUNCH_ID}`);
output.debug(`Starting ReportPortal aggregate launch: ${id}`);
});
isControlThread = true;
});

event.dispatcher.on(event.all.before, () => {
launchObj = startLaunch();
launchObj.promise.catch(err => {
output.error('Can`\t connect to ReportPortal');
output.error(err);
});
output.print('Logging results to ReportPortal');
debug(`${launchObj.tempId}: The launchId is started.`);
recorder.add('launch report portal', async () => {
launchObj = startLaunch();
})
});

event.dispatcher.on(event.suite.before, (suite) => {
if (isControlThread) return;
recorder.add(async () => {
suiteObj = startTestItem(suite.title, rp_SUITE);
debug(`${suiteObj.tempId}: The suiteId '${suite.title}' is started.`);
Expand Down Expand Up @@ -111,6 +121,7 @@ module.exports = (config) => {
});

event.dispatcher.on(event.test.failed, async (test, err) => {
if (isControlThread) return;
launchStatus = rp_FAILED;
suiteStatus = rp_FAILED;

Expand All @@ -136,6 +147,7 @@ module.exports = (config) => {
});

event.dispatcher.on(event.test.passed, (test, err) => {
if (isControlThread) return;
debug(`${test.tempId}: Test '${test.title}' passed.`);
rpClient.finishTestItem(test.tempId, {
endTime: test.endTime || rpClient.helpers.now(),
Expand All @@ -144,6 +156,7 @@ module.exports = (config) => {
});

event.dispatcher.on(event.test.after, (test) => {
if (isControlThread) return;
recorder.add(async () => {
debug(`closing ${currentMetaSteps.length} metasteps for failed test`);
if (failedStep) await finishStep(failedStep);
Expand All @@ -152,6 +165,7 @@ module.exports = (config) => {
});

event.dispatcher.on(event.suite.after, (suite) => {
if (isControlThread) return;
recorder.add(async () => {
debug(`${suite.tempId}: Suite '${suite.title}' finished ${suiteStatus}.`);
return rpClient.finishTestItem(suite.tempId, {
Expand All @@ -172,16 +186,16 @@ module.exports = (config) => {
} catch (error) {
output.err(error);
}

}

event.dispatcher.on(event.all.result, () => {
recorder.add(async () => {
// await suiteObj.promise;
await rpClient.finishTestItem(suiteObj.tempId, {
// close outstanding items
if (!isControlThread) await rpClient.finishTestItem(suiteObj.tempId, {
status: suiteStatus,
}).promise;
finishLaunch();
// stop launch when we are in main thread (control or normal)
if (isMainThread) finishLaunch();
});
});

Expand All @@ -193,12 +207,33 @@ module.exports = (config) => {
debug: config.debug,
});

return rpClient.startLaunch({
const launchOpts = {
name: config.launchName || suiteTitle,
description: config.launchDescription,
attributes: config.launchAttributes,
rerun: config.rerun,
rerunOf: config.rerunOf,
};

if (process.env.RP_LAUNCH_ID) {
launchOpts.id = process.env.RP_LAUNCH_ID;
}

const launch = rpClient.startLaunch(launchOpts);

launch.promise.catch(err => {
output.error('Can`\t connect to ReportPortal');
output.error(err);
});
output.print('Logging results to ReportPortal');
debug(`${launch.tempId}: The launchId is started.`);

return launch.promise.then((response) => {
if (isControlThread) {
process.env.RP_LAUNCH_ID = response.id;
debug('setting launch id to RP_LAUNCH_ID for parallel run');
}
return response;
});
}

Expand Down