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

wait for Temp directory is initialized for video recording (closes #3508) #3577

Merged
merged 2 commits into from
Mar 20, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/video-recorder/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ export default class VideoRecorder {
}

_assignEventHandlers (browserJob) {
browserJob.once('start', this._createSafeListener(this._onBrowserJobStart));
browserJob.once('start', this._createSafeListener(() => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add the async modifier and add await this.tempDirectoryInitializedPromise OR return this.tempDirectoryInitializedPromise from the handler.

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));
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down
71 changes: 71 additions & 0 deletions test/server/video-recorder-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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'
]);
});
});
});