Fix #4256 : write webdriver/chromedriver logs per worker in parallel mode - #4424
Fix #4256 : write webdriver/chromedriver logs per worker in parallel mode#4424Samriddhi-35 wants to merge 7 commits into
Conversation
…allel with test workers
Status
|
…arallel mode and use timestamp instead of worker id >
There was a problem hiding this comment.
Pull request overview
This PR fixes an issue where webdriver/chromedriver log files were not being generated when Nightwatch runs tests in parallel mode (using worker threads or child processes). The fix enables log file creation in worker processes and ensures each worker generates a uniquely-named log file using high-resolution timestamps.
Key Changes:
- Modified
needsSinkProcess()to allow log retention in worker processes whenretain_logs_in_workeris enabled - Added timestamp-based unique naming for log files in parallel mode to prevent conflicts between workers
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| lib/transport/selenium-webdriver/service-builders/base-service.js | Updated needsSinkProcess() to support log retention in workers via retain_logs_in_worker config option; minor formatting adjustments |
| lib/transport/selenium-webdriver/index.js | Added logic to append timestamps to log file names in worker mode for unique per-worker log files; imported Concurrency module |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| async createDriverService({options, moduleKey, reuseBrowser = false}) { | ||
| try { | ||
| moduleKey = this.settings.webdriver.log_file_name || moduleKey || ''; | ||
| if (Concurrency.isWorker) { |
There was a problem hiding this comment.
Concurrency.isWorker is a static method and should be called as a function with parentheses. Currently, it's being accessed as a property, which will always evaluate to a truthy value (the function object itself) rather than executing the function to check if the current process is a worker. This means the timestamp logic will execute in all scenarios, not just in worker mode as intended. Change to Concurrency.isWorker().
| if (Concurrency.isWorker) { | |
| if (Concurrency.isWorker()) { |
| return !Concurrency.isWorker(); | ||
| const {retain_logs_in_worker} = this.settings.webdriver || {}; | ||
|
|
||
| return !Concurrency.isWorker() || retain_logs_in_worker ; |
There was a problem hiding this comment.
There is a trailing space after retain_logs_in_worker before the semicolon. Remove the extra whitespace for consistent code formatting.
| return !Concurrency.isWorker() || retain_logs_in_worker ; | |
| return !Concurrency.isWorker() || retain_logs_in_worker; |
|
Completed in #4440 after rebasing the changes from this branch. Thanks for working on this! |
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 and a generated random string of length 10(e.g.,
my_custom_log_<timestamp>_abcd1234ef.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: