Run Flamenco Unit Tests in the local timezone #104236

Manually merged
Sybren A. Stüvel merged 2 commits from michael-2/flamenco:mock_test_timezone_aware into main 2023-08-23 16:08:37 +02:00
3 changed files with 8 additions and 7 deletions
Showing only changes of commit db30f6f417 - Show all commits

View File

@ -57,7 +57,8 @@ func exampleSubmittedJob() api.SubmittedJob {
func mockedClock(t *testing.T) clock.Clock { func mockedClock(t *testing.T) clock.Clock {
c := clock.NewMock() c := clock.NewMock()
now, err := time.Parse(time.RFC3339, "2006-01-02T15:04:05+07:00") //current_location, err := time.LoadLocation("Local")

Please remove the commented-out code.

Please remove the commented-out code.
now, err := time.ParseInLocation("2006-01-02T15:04:05", "2006-01-02T15:04:05", time.Local)
assert.NoError(t, err) assert.NoError(t, err)
c.Set(now) c.Set(now)
return c return c
@ -250,13 +251,13 @@ func TestSimpleBlenderRenderOutputPathFieldReplacement(t *testing.T) {
require.NotNil(t, aj) require.NotNil(t, aj)
// The job compiler should have replaced the {timestamp} and {ext} fields. // The job compiler should have replaced the {timestamp} and {ext} fields.
assert.Equal(t, "/root/2006-01-02_090405/jobname/######", aj.Settings["render_output_path"]) assert.Equal(t, "/root/2006-01-02_150405/jobname/######", aj.Settings["render_output_path"])
dr.sybren marked this conversation as resolved

This was intentionally using a mocked clock in a different timezone, and ensuring that the created timestamp is in UTC. By moving this all to the local timezone, the test semantics are changed.

This was intentionally using a mocked clock in a different timezone, and ensuring that the created timestamp is in UTC. By moving this all to the local timezone, the test semantics are changed.
Review

I did wonder about that but moved it to local timezone. I didn't realise it was intentionally a timezone test. I can fix that back up to test UTC timestamps.

I did wonder about that but moved it to local timezone. I didn't realise it was intentionally a timezone test. I can fix that back up to test UTC timestamps.
// Tasks should have been created to render the frames: 1-3, 4-6, 7-9, 10, and video-encoding // Tasks should have been created to render the frames: 1-3, 4-6, 7-9, 10, and video-encoding
require.Len(t, aj.Tasks, 5) require.Len(t, aj.Tasks, 5)
t0 := aj.Tasks[0] t0 := aj.Tasks[0]
expectCliArgs := []interface{}{ // They are strings, but Goja doesn't know that and will produce an []interface{}. expectCliArgs := []interface{}{ // They are strings, but Goja doesn't know that and will produce an []interface{}.
"--render-output", "/root/2006-01-02_090405/jobname/######", "--render-output", "/root/2006-01-02_150405/jobname/######",
"--render-format", sj.Settings.AdditionalProperties["format"].(string), "--render-format", sj.Settings.AdditionalProperties["format"].(string),
"--render-frame", "1..3", "--render-frame", "1..3",
} }
@ -271,8 +272,8 @@ func TestSimpleBlenderRenderOutputPathFieldReplacement(t *testing.T) {
tVideo := aj.Tasks[4] // This should be a video encoding task tVideo := aj.Tasks[4] // This should be a video encoding task
assert.EqualValues(t, AuthoredCommandParameters{ assert.EqualValues(t, AuthoredCommandParameters{
"exe": "ffmpeg", "exe": "ffmpeg",
"inputGlob": "/root/2006-01-02_090405/jobname/*.png", "inputGlob": "/root/2006-01-02_150405/jobname/*.png",
"outputFile": "/root/2006-01-02_090405/jobname/scene123-1-10.mp4", "outputFile": "/root/2006-01-02_150405/jobname/scene123-1-10.mp4",
"fps": int64(24), "fps": int64(24),
"args": expectedFramesToVideoArgs, "args": expectedFramesToVideoArgs,
}, tVideo.Commands[0].Parameters) }, tVideo.Commands[0].Parameters)

View File

@ -269,7 +269,7 @@ func testFixtures(t *testing.T) (*SleepScheduler, TestMocks, context.Context) {
ctx := context.Background() ctx := context.Background()
mockedClock := clock.NewMock() mockedClock := clock.NewMock()
mockedNow, err := time.Parse(time.RFC3339, "2022-06-07T11:14:47+02:00") mockedNow, err := time.ParseInLocation("2006-01-02T15:04:05", "2022-06-07T11:14:47", time.Local)

The sleep scheduler should work well (that is, always treat the schedule as local time), regardless of whether the mocked clock is set to local time or not. I've taken the liberty of addressing this myself in eb9f46dc9b, so this change can be removed from this PR.

The sleep scheduler should work well (that is, always treat the schedule as local time), regardless of whether the mocked clock is set to local time or not. I've taken the liberty of addressing this myself in eb9f46dc9b5212e99d44899e0c298f17610f2a24, so this change can be removed from this PR.
if err != nil { if err != nil {
panic(err) panic(err)
} }

View File

@ -12,7 +12,7 @@ import (
func mockedClock(t *testing.T) *clock.Mock { func mockedClock(t *testing.T) *clock.Mock {
c := clock.NewMock() c := clock.NewMock()
now, err := time.Parse(time.RFC3339, "2006-01-02T15:04:05+07:00") now, err := time.ParseInLocation("2006-01-02T15:04:05", "2006-01-02T15:04:05", time.Local)
assert.NoError(t, err) assert.NoError(t, err)
c.Set(now) c.Set(now)
return c return c