Skip to content

Commit

Permalink
wait for Temp directory is initialized for video recording (closes De…
Browse files Browse the repository at this point in the history
…vExpress#3508) (DevExpress#3577)

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

* return promise
  • Loading branch information
AlexKamaev authored and kirovboris committed Dec 18, 2019
1 parent 6c51e2c commit 132724e
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/video-recorder/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,12 @@ export default class VideoRecorder {
}

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

return this.tempDirectoryInitializedPromise;
}));

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 +97,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 +153,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'
]);
});
});
});

0 comments on commit 132724e

Please sign in to comment.