tomyam1 / protractor-video-reporter

Jasmine reporter that captures a screencast of Protractor specs running on a headless browser, e.g. in CI server
MIT License
21 stars 21 forks source link

Unstable way to delete videos after killing FFmpeg process #2

Closed 7-mb closed 8 years ago

7-mb commented 8 years ago

When I use saveSuccessVideos: false, I received the error that it is not possible to delete the not needed videos. The call Fs.unlinkSync(self._videoPath); provokes the following error:

Video removed
[launcher] Process exited with error code 1
>> Error: EBUSY: resource busy or locked, unlink 'D:\selenium_screen_videos\...'
>>     at Error (native)
>>     at Object.fs.unlinkSync (fs.js:937:18)
>>     at VideoReporter.specDone (D:\...\node_modules\protractor-video-reporter\lib\VideoReporter.js:144:8)

I think that the problem is that the FFmpeg process is not killed fast enough. Because after I added sleep.sleep(10); after self._ffmpeg.kill();, it worked.

But I think it would be better to check if the FFmpeg process is still running before calling the unlinkSync() command.

7-mb commented 8 years ago

I did a workaround which deletes the videos of successful test cases not immediately after the single test case but only after the WebDriver's instance is finished.

So I added into my config file:

[...]
    onPrepare: function () {
        global.videosToDelete = [];
[...]
    onComplete: function () {
        var Fs = require('fs');
        global.deleteNotNeededVideos = function () {
            console.log('delete not needed videos');
            console.log(videosToDelete);
            var del = videosToDelete;
            videosToDelete = [];
            for (var i = 0; i < del.length; i++) {
                Fs.unlink(del[i], function (err) {
                    if (err) {
                        videosToDelete.push(del[i]);
                        return;
                    }
                });
            }
        };

        deleteNotNeededVideos();
    }
[...]

and adjusted in VideoReporter.js:

[...]
  // Remove it otherwise
  } else {
    self.debug('Video removed');
    //Fs.unlinkSync(self._videoPath); --> method is not stable at this point!
    videosToDelete.push(self._videoPath);
  }
[...]

This approach deletes the videos reliably for me.