Worker: fix FFmpeg issues on Windows

Fix the FFmpeg unit test on Windows, by:
- Having actual input files (otherwise the input-glob-creation-function
  errors out), and
- ensuring the cleanup function is always run, and
- testing for the right CLI arguments.
This commit is contained in:
Sybren A. Stüvel 2022-05-19 16:42:40 +02:00
parent f4299018ef
commit dbd32e56cd
5 changed files with 22 additions and 8 deletions

View File

@ -116,7 +116,17 @@ func (ce *CommandExecutor) cmdFramesToVideoExeCommand(
}
inputGlobArgs, cleanup, err := parameters.getInputGlob()
// runCleanup should be used if the cleanup function is *not* going to be
// returned (i.e. in case of error).
runCleanup := func() {
if cleanup != nil {
cleanup()
}
}
if err != nil {
runCleanup()
return nil, nil, fmt.Errorf("creating input for FFmpeg: %w", err)
}
@ -128,6 +138,7 @@ func (ce *CommandExecutor) cmdFramesToVideoExeCommand(
execCmd := ce.cli.CommandContext(ctx, parameters.exe, cliArgs...)
if execCmd == nil {
runCleanup()
logger.Error().Msg("unable to create command executor")
return nil, nil, ErrNoExecCmd
}
@ -136,6 +147,7 @@ func (ce *CommandExecutor) cmdFramesToVideoExeCommand(
Msg("going to execute FFmpeg")
if err := ce.listener.LogProduced(ctx, taskID, fmt.Sprintf("going to run: %s %q", parameters.exe, cliArgs)); err != nil {
runCleanup()
return nil, nil, err
}

View File

@ -70,8 +70,9 @@ func TestCmdFramesToVideoSimpleWindows(t *testing.T) {
Parameters: map[string]interface{}{
"exe": "/path/to/ffmpeg -v quiet",
"argsBefore": []string{"-report"},
"inputGlob": "path/to/renders/*.png",
"fps": 10.0,
// NOTE: these files MUST exist, otherwise the glob index file creation will fail.
"inputGlob": "command_ffmpeg_test_files/*.png",
"fps": 10.0,
"args": []string{
"-c:v", "hevc",
"-crf", "31",
@ -83,8 +84,8 @@ func TestCmdFramesToVideoSimpleWindows(t *testing.T) {
cliArgs := []string{
"-v", "quiet", // exe
"-report", // argsBefore
"-f", "concat", "-i", "this-is-random.txt", // input glob
"-report", // argsBefore
"-f", "concat", "-safe", "0", "-i", "command_ffmpeg_test_files\\ffmpeg-file-index.txt", // input glob
"-c:v", "hevc", "-crf", "31", "-vf", "pad=ceil(iw/2)*2:ceil(ih/2)*2", // args
"-r", "10", // fps
"path/to/renders/preview.mkv", // outputFile
@ -92,12 +93,13 @@ func TestCmdFramesToVideoSimpleWindows(t *testing.T) {
mocks.cli.EXPECT().
CommandContext(gomock.Any(), "/path/to/ffmpeg", gomock.Any()).
DoAndReturn(func(ctx context.Context, name string, arg ...string) error {
// Test all but the random filename.
assert.EqualValues(t, cliArgs[:6], arg[:6])
assert.EqualValues(t, cliArgs[7:], arg[7:])
return nil
assert.EqualValues(t, cliArgs, arg)
return nil // this is the nil *exec.Cmd referenced below
})
err := ce.cmdFramesToVideo(context.Background(), zerolog.Nop(), taskID, cmd)
assert.Equal(t, ErrNoExecCmd, err, "nil *exec.Cmd should result in ErrNoExecCmd")
assert.NoFileExists(t, "command_ffmpeg_test_files/ffmpeg-file-index.txt",
"the glob index file should have been removed")
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB