selenium: improve ffmpeg reporting
authorAntoine Musso <hashar@free.fr>
Thu, 21 Feb 2019 16:00:32 +0000 (17:00 +0100)
committerAntoine Musso <hashar@free.fr>
Mon, 25 Feb 2019 16:03:13 +0000 (17:03 +0100)
1) stdout/stderr log improvement

Our wdio test suite records video of Selenium test session using ffmpeg,
its stdout/stderr are relayed via console.log() however the new line was
not stripped which is confusing and in case the buffer contains multiple
lines, only the first line had the 'ffmpeg stderr: ' prefix.

Ensure each ffmpeg line is prefixed by logging them individually.

2) exit code / signal

childProcess 'close' event is being passed the exit code and the signal.
We only handled the exit code, thus when ffmpeg is send a signal we
logged:

  ffmpeg exited with code null

Handle the case when the childProcess is send a signal (typically
SIGINT).

Change-Id: I9f509690baa9b7981399a09448582f45c30800d7

tests/selenium/wdio.conf.js

index 11be135..bdabdbf 100644 (file)
@@ -154,6 +154,7 @@ exports.config = {
        */
        beforeTest: function ( test ) {
                if ( process.env.DISPLAY && process.env.DISPLAY.startsWith( ':' ) ) {
+                       var logBuffer;
                        let videoPath = filePath( test, logPath, 'mp4' );
                        const { spawn } = require( 'child_process' );
                        ffmpeg = spawn( 'ffmpeg', [
@@ -166,17 +167,29 @@ exports.config = {
                                videoPath // output file
                        ] );
 
+                       logBuffer = function ( buffer, prefix ) {
+                               let lines = buffer.toString().trim().split( '\n' );
+                               lines.forEach( function ( line ) {
+                                       console.log( prefix + line );
+                               } );
+                       };
+
                        ffmpeg.stdout.on( 'data', ( data ) => {
-                               console.log( `ffmpeg stdout: ${data}` );
+                               logBuffer( data, 'ffmpeg stdout: ' );
                        } );
 
                        ffmpeg.stderr.on( 'data', ( data ) => {
-                               console.log( `ffmpeg stderr: ${data}` );
+                               logBuffer( data, 'ffmpeg stderr: ' );
                        } );
 
-                       ffmpeg.on( 'close', ( code ) => {
+                       ffmpeg.on( 'close', ( code, signal ) => {
                                console.log( '\n\tVideo location:', videoPath, '\n' );
-                               console.log( `ffmpeg exited with code ${code}` );
+                               if ( code !== null ) {
+                                       console.log( `\tffmpeg exited with code ${code} ${videoPath}` );
+                               }
+                               if ( signal !== null ) {
+                                       console.log( `\tffmpeg received signal ${signal} ${videoPath}` );
+                               }
                        } );
                }
        },