From a9190dfa495f28f438b5f9c3fdbbb32e426ddb88 Mon Sep 17 00:00:00 2001 From: Alex Kamaev Date: Mon, 18 Mar 2019 18:35:08 +0300 Subject: [PATCH 1/2] wait for Temp directory is initialized for video recording (closes #3508) --- src/video-recorder/index.js | 12 +++-- test/server/video-recorder-test.js | 71 ++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+), 4 deletions(-) diff --git a/src/video-recorder/index.js b/src/video-recorder/index.js index 76b39d51756..64c87ecc287 100644 --- a/src/video-recorder/index.js +++ b/src/video-recorder/index.js @@ -58,7 +58,10 @@ export default class VideoRecorder { } _assignEventHandlers (browserJob) { - browserJob.once('start', this._createSafeListener(this._onBrowserJobStart)); + browserJob.once('start', this._createSafeListener(() => { + this.tempDirectoryInitializedPromise = this._onBrowserJobStart(); + })); + browserJob.once('done', this._createSafeListener(this._onBrowserJobDone)); browserJob.on('test-run-create', this._createSafeListener(this._onTestRunCreate)); browserJob.on('test-run-ready', this._createSafeListener(this._onTestRunReady)); @@ -92,13 +95,15 @@ export default class VideoRecorder { return join(this.basePath, pathPattern.getPath()); } - _generateTempNames (id) { + async _generateTempNames (id) { const tempFileNames = { tempVideoPath: `${TEMP_VIDEO_FILE_PREFIX}-${id}.${VIDEO_EXTENSION}`, tempMergeConfigPath: `${TEMP_MERGE_CONFIG_FILE_PREFIX}-${id}.${TEMP_MERGE_CONFIG_FILE_EXTENSION}`, tmpMergeName: `${TEMP_MERGE_FILE_PREFIX}-${id}.${VIDEO_EXTENSION}` }; + await this.tempDirectoryInitializedPromise; + for (const [tempFile, tempName] of Object.entries(tempFileNames)) tempFileNames[tempFile] = join(this.tempDirectory.path, tempName); @@ -146,8 +151,7 @@ export default class VideoRecorder { this.testRunInfo[index] = testRunInfo; - testRunInfo.tempFiles = this._generateTempNames(connection.id); - + testRunInfo.tempFiles = await this._generateTempNames(connection.id); testRunInfo.videoRecorder = new VideoRecorderProcess(testRunInfo.tempFiles.tempVideoPath, this.ffmpegPath, connection, this.encodingOptions); diff --git a/test/server/video-recorder-test.js b/test/server/video-recorder-test.js index c32116801ce..73f3f928ede 100644 --- a/test/server/video-recorder-test.js +++ b/test/server/video-recorder-test.js @@ -5,6 +5,41 @@ const WarningLog = require('../../lib/notifications/warning-log'); const VIDEOS_BASE_PATH = '__videos__'; +class VideoRecorderMock extends VideoRecorder { + constructor (basePath, ffmpegPath, connection, customOptions) { + super(basePath, ffmpegPath, connection, customOptions); + + this.log = []; + } + + _generateTempNames (id) { + return super._generateTempNames(id) + .then(result => { + this.log.push('generate-names'); + + return result; + }); + } + + _onBrowserJobStart () { + this.log.push('job-start'); + + return super._onBrowserJobStart() + .then(() => { + this.log.push('temp-dir-initialized'); + }); + } + + _onTestRunCreate (options) { + this.log.push('test-created'); + + return super._onTestRunCreate(options) + .then(() => { + this.log.push('video-recorder-initialized'); + }); + } +} + describe('Video Recorder', () => { it('Should not start video recording for legacy tests', () => { const browserJobMock = new AsyncEmitter(); @@ -46,4 +81,40 @@ describe('Video Recorder', () => { 'The placeholders were replaced with an empty string.' ]); }); + + it('Should wait for Temp directory is initialized', () => { + const browserJobMock = new AsyncEmitter(); + const warningLog = new WarningLog(); + const videoRecorder = new VideoRecorderMock(browserJobMock, VIDEOS_BASE_PATH, {}, {}, warningLog); + + const testRunMock = { + testRun: { + browserConnection: { + id: 'connectionId', + provider: { + hasCustomActionForBrowser: () => { + return { + hasGetVideoFrameData: true + }; + } + } + } + } + }; + + browserJobMock.emit('start'); + + const testRunCreatePromise = browserJobMock.emit('test-run-create', testRunMock); + + browserJobMock.emit('done'); + + return testRunCreatePromise.then(() => { + expect(videoRecorder.log).eql([ + 'job-start', + 'test-created', + 'temp-dir-initialized', + 'generate-names' + ]); + }); + }); }); From 1d27ef892f6329c321756ea2b49f33d2990ee7d1 Mon Sep 17 00:00:00 2001 From: Alex Kamaev Date: Tue, 19 Mar 2019 14:19:52 +0300 Subject: [PATCH 2/2] return promise --- src/video-recorder/index.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/video-recorder/index.js b/src/video-recorder/index.js index 64c87ecc287..928f0aa2bb5 100644 --- a/src/video-recorder/index.js +++ b/src/video-recorder/index.js @@ -60,6 +60,8 @@ export default class VideoRecorder { _assignEventHandlers (browserJob) { browserJob.once('start', this._createSafeListener(() => { this.tempDirectoryInitializedPromise = this._onBrowserJobStart(); + + return this.tempDirectoryInitializedPromise; })); browserJob.once('done', this._createSafeListener(this._onBrowserJobDone));