Skip to content

How does run-workers work?  #1934

@orihomie

Description

@orihomie

What are you trying to achieve?

I'm tryin to execute command:

npx codeceptjs run-workers 2 [4, 8]

and I expect to get as much chrome browsers as workers count

What do you get instead?

1-2 chrome opens and that's it, no more browser windows (cpu and mem are enough atm)

Details

  • CodeceptJS version: 2.3.1
  • NodeJS Version: 12.10.0
  • Operating System: MacOS Mojave
  • TestCafe: 1.5.0
  • Configuration file:
exports.config = {
	tests: './*_test.js',
	output: './output',
	helpers: {
		TestCafe: {
			url: 'myUrl',
			browser: 'chrome',
			show: true
		},
		MailSlurp: {
			require: '@codeceptjs/mailslurp-helper',
			apiKey: 'validApiKey',
			timeout: 60000
		},
	},
	include: {
		"mainPage": "../pages/mainPage.js",
		"osagoPage": "../pages/osagoPage.js",
		"userClicksForgotNumber": "./steps/userClicksForgotNumber.js",
		"userSavesStateByEmail": "./steps/userSavesStateByEmail.js"
	},
	bootstrap: null,
	mocha: {},
	name: 'productName',
	translation: 'ru-RU',
	timeout: 10000
};

UPD 1.
When I've executed command:

npx codeceptjs run-workers 2 --verbose

There were spawned multiple errors all containing this:

[1] Error | Error: The specified 1341 port is already in use by another program.

UPD 2.
I've digged into code, first codeceptjs's, then testCafe's and, boy, what do I see:

async function getValidPort(port) {
    if (port) {
        const isFree = await endpointUtils.isFreePort(port);
        if (!isFree)
            throw new runtime_1.GeneralError(types_1.RUNTIME_ERRORS.portIsNotFree, port);
    }
    else
        port = await endpointUtils.getFreePort();
    return port;
}

TestCafe can manage ports by its own, so, why do we need this kind of management:

// in ctor
this.iteration = 1;
...
// and then
async _startBrowser() {
    this.dummyTestcafeFile = createTestFile(global.output_dir); // create a dummy test file to get hold of the test controller

    this.iteration += 2; // Use different ports for each test run
    // @ts-ignore
    this.testcafe = await createTestCafe('localhost', 1338 + this.iteration, 1339 + this.iteration);

Why can't we just pass null to a ports in previous line?

UPD 3.
I've made a fork and applied my suggestions and that works

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions