Log in parallel modes - #4440
Conversation
Status
|
…allel with test workers
…arallel mode and use timestamp instead of worker id >
5709f17 to
61c1c0c
Compare
e2e7bf9 to
2eb0a92
Compare
There was a problem hiding this comment.
Pull request overview
This PR fixes missing webdriver/chromedriver log files when Nightwatch runs tests in parallel mode (using worker threads or child processes). Previously, the log sink was disabled in worker processes, causing writeLogFile() to no-op and resulting in no log files for worker-hosted driver processes.
Changes:
- Modified
needsSinkProcess()to respect a newretain_logs_in_workerconfiguration option, allowing logs to be generated in parallel workers - Added timestamp suffixes to log file names in worker contexts using
process.hrtime.bigint()to ensure unique file names - Added comprehensive tests for the new concurrency logging behavior
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 10 comments.
| File | Description |
|---|---|
| lib/transport/selenium-webdriver/service-builders/base-service.js | Modified needsSinkProcess() to check retain_logs_in_worker setting and allow sink process creation in workers; minor formatting changes |
| lib/transport/selenium-webdriver/index.js | Added timestamp suffix to log file names when running in worker mode to prevent file name collisions |
| test/src/service-builders/testSeleniumServer.js | Added test to verify per-worker log file path includes timestamp when running as worker |
| test/src/service-builders/testBaseServiceConcurrency.js | New test file with comprehensive tests for sink process creation behavior in different concurrency scenarios |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Made-with: Cursor
Made-with: Cursor
Restore and override Concurrency.isWorker deterministically per test case so worker/non-worker assertions are stable on Windows and other platforms. Made-with: Cursor
Mock the exact concurrency module path loaded by BaseService so isWorker stubbing is reliable with clean module cache on Windows. Made-with: Cursor
Concurrency.isWorker() reads __NIGHTWATCH_PARALLEL_MODE on each call, so setting it avoids mockery/cache issues across platforms. Made-with: Cursor
|
@shubhamkd This PR looks good now. The only thing remaining now is the two open Copilot comments (TypeScript type and default value addition), and the documentation for this feature. |
Add the option to defaults.js and the WebdriverOptions TypeScript interface so users can discover it and TS consumers don't get type errors when setting it. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
LGTM! Thank you for working on this @Samriddhi-35 @shubhamkd |
This PR fixes missing webdriver / chromedriver log files when Nightwatch runs tests in parallel (worker-threads or child-process workers). Previously worker-mode disabled the log sink, causing writeLogFile() to no-op and resulting in no log files for worker-hosted driver processes.
Root cause
BaseService.needsSinkProcess()returned false in workers whenConcurrency.isWorker()was true, soBaseService.createService()set[webdriver.log_path = false]for workers. That madegetLogPath()return null andwriteLogFile()return early and hence no file was written.Changes Implemented
Parallel Mode-Specific Logging Behavior
When parallel mode is detected (
process.env.__NIGHTWATCH_PARALLEL_MODE === '1'), unique log files are created for each Chromedriver instance spun up:Without
log_file_name:Log files are named as
<module_key>_<timestamp>.log, where<timestamp>is dynamically generated.With
log_file_name:User-configured log file names (e.g.,
my_custom_log) are suffixed with timestamp.(e.g.,
my_custom_log_<timestamp>.log).Fallback to Default Behavior for Non-Parallel Execution
If parallel mode is not enabled or only a single thread is used:
Files changed
lib/transport/selenium-webdriver/index.jslib/transport/selenium-webdriver/service-builders/base-service.jsHow to test (locally)
npx nightwatch tests/guide/ --env chrome --workers=2webdriver.log_path(defaults to./logs):ls -l logs/andhead -n 50 logs/<file>.Notes
hasSinkSupport()still respected).After Changes
log_file_name:-With

log_file_name: