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

Reduce number of created temp dirs for profiles (closes #2735, closes #2013) #2740

Merged
merged 5 commits into from
Aug 24, 2018

Conversation

AndreyBelym
Copy link
Contributor

No description provided.

@testcafe-build-bot
Copy link
Collaborator

❌ Tests for the commit a18e1d6 have failed. See details:

@AndreyBelym AndreyBelym changed the title [WIP] Reduce number of created temp dirs for profiles (closes #2735) Reduce number of created temp dirs for profiles (closes #2735) Aug 17, 2018
@testcafe-build-bot
Copy link
Collaborator

✅ Tests for the commit 95a21d5 have passed. See details:

Copy link
Collaborator

@kirovboris kirovboris left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/r-


const tempDir = tmp.dirSync({ unsafeCleanup: true });
const profileDirName = path.join(tempDir.name, 'Default');
const tempDir = await TempDirectory.createDirectory('chrome-profile');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be testcafe-chrome-profile to avoid the name conflicts.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Solved in favor of top-level testcafe-tmp.

@@ -54,11 +54,9 @@ async function generatePreferences (profileDir, { marionettePort, config }) {
}

export default async function (runtimeInfo) {
tmp.setGracefulCleanup();
const tmpDir = await TempDirectory.createDirectory('firefox-profile');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

testcafe-firefox-profile

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Solved in favor of top-level testcafe-tmp.

export default async function (proxyHostName, configString) {
var config = getConfig(configString);
var tempProfileDir = !config.userProfile ? await getTempProfile(proxyHostName, config) : null;
var tempProfileDir = !config.userProfile ? await createTempProfile(proxyHostName, config) : null;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

replace var to const.



// NOTE: mutable for testing purposes
let TESTCAFE_TMP_DIRS_ROOT = path.join(os.tmpdir(), 'testcafe-tmp');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we can rename testcafe-tmp to testcafe because this folder is already placed in temporary directory.

this.path = path.join(dirPath, LOCKFILE_NAME);
}

_openLockFile () {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unneeded context: rename openLockFile to _open.


const DEBUG_LOGGER = debug('testcafe:utils:temp-directory');

class LockFile {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move LockFile and TempDirectory to separate files.

}
}

_isStaleLockFile () {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unneeded context: rename to _isStale

const TempDirectory = require('../../lib/utils/temp-directory');


const TMP_ROOT = path.join(process.cwd(), '__tmp__');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This constant is used only in `describe('Temp Directory',). So move it.

@testcafe-build-bot
Copy link
Collaborator

❌ Tests for the commit 15231be have failed. See details:

@testcafe-build-bot
Copy link
Collaborator

❌ Tests for the commit 16b8770 have failed. See details:

@testcafe-build-bot
Copy link
Collaborator

✅ Tests for the commit 16b8770 have passed. See details:

@AndreyBelym
Copy link
Contributor Author

FPR

@AndreyBelym AndreyBelym changed the title Reduce number of created temp dirs for profiles (closes #2735) Reduce number of created temp dirs for profiles (closes #2735, closes #2013) Aug 21, 2018
@AndreyBelym
Copy link
Contributor Author

\cc @miherlosev @kirovboris

I've tested in on Windows 10, Ubuntu 16.04 VM, macOS 10.13 VM.

Additional detached process for killing browsers and cleaning temp dirs works even for #2013

You can grab a debug build here for testing: https://github.com/AndreyBelym/testcafe/releases/tag/build-gh-2735

Copy link
Collaborator

@kirovboris kirovboris left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/r-

// NOTE: mutable for testing purposes
let TESTCAFE_TMP_DIRS_ROOT = path.join(os.tmpdir(), 'testcafe');

const DEFAULT_NAME_PREFIX = 'tmp';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incorrect indentation

const DEFAULT_NAME_PREFIX = 'tmp';

const USED_TEMP_DIRS = {};

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need so many empty string between constants. I wouldn't say it improve the readability.


DEBUG_LOGGER('Temp directory path: ', this.path);

await cleanupProcess.init();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

await cleanupProcess.init();
await cleanupProcess.addDirectory(this.path);

USED_TEMP_DIRS[this.path] = this;
}

disposeSync () {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not a public method.

}

// NOTE: for testing purposes
static get TEMP_DIRECTORIES_ROOT () {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not

exports.TEMP_DIRECTORIES_ROOT = TEMP_DIRECTORIES_ROOT = ;

?
Otherwise a static variable should be initialized in the class.

}

init () {
this.initPromise = this.initPromise
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does it work? Is it the workaround for the concurrent init?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's a guard that ensures that init code will be run sequentially when called concurrently. This situation can happen when starting both Chrome and Firefox, or in concurrency mode. Calls to init form a Promise chain, where each next call have to wait until all previous calls are resolved.

}
}

function init () {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does this function needed, if we already execute it in module context?

process.on('disconnect', async () => {
const removePromises = Object
.keys(DIRECTORIES_TO_CLEANUP)
.map(dirPath => removeDirectory(dirPath).catch(() => {}));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer noop, because our auto-complete settings unfolds () => {} in

() => {
}

addDirectory(message.path);
await removeDirectory(message.path);
return;
default:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we use default here, is it for the eslint purposes?


_open ({ force = false } = {}) {
try {
const fd = fs.openSync(this.path, force ? 'w' : 'wx');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can add flag in writeFileSync as well.

@testcafe-build-bot
Copy link
Collaborator

❌ Tests for the commit bb6d513 have failed. See details:

@testcafe-build-bot
Copy link
Collaborator

✅ Tests for the commit bb6d513 have passed. See details:

@miherlosev miherlosev merged commit 433d608 into DevExpress:master Aug 24, 2018
kirovboris pushed a commit to kirovboris/testcafe-phoenix that referenced this pull request Dec 18, 2019
…, closes DevExpress#2013) (DevExpress#2740)

* Reduce number of created temp dirs for profiles (closes DevExpress#2735)

* Add test

* Remove temp dirs in a separate process

* Fix tests

* Fix remarks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants