Sync branch magefile with main #104308
@ -762,17 +762,12 @@ func createTestAuthoredJob(jobID string, tasks ...job_compilers.AuthoredTask) jo
|
|||||||
|
|
||||||
func persistAuthoredJob(t *testing.T, ctx context.Context, db *DB, authoredJob job_compilers.AuthoredJob) *Job {
|
func persistAuthoredJob(t *testing.T, ctx context.Context, db *DB, authoredJob job_compilers.AuthoredJob) *Job {
|
||||||
err := db.StoreAuthoredJob(ctx, authoredJob)
|
err := db.StoreAuthoredJob(ctx, authoredJob)
|
||||||
if err != nil {
|
require.NoError(t, err, "error storing authored job in DB")
|
||||||
t.Fatalf("error storing authored job in DB: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
dbJob, err := db.FetchJob(ctx, authoredJob.JobID)
|
dbJob, err := db.FetchJob(ctx, authoredJob.JobID)
|
||||||
if err != nil {
|
require.NoError(t, err, "error fetching job from DB")
|
||||||
t.Fatalf("error fetching job from DB: %v", err)
|
require.NotNil(t, dbJob, "nil job obtained from DB but with no error!")
|
||||||
}
|
|
||||||
if dbJob == nil {
|
|
||||||
t.Fatalf("nil job obtained from DB but with no error!")
|
|
||||||
}
|
|
||||||
return dbJob
|
return dbJob
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -849,18 +844,11 @@ func createWorker(ctx context.Context, t *testing.T, db *DB, updaters ...func(*W
|
|||||||
}
|
}
|
||||||
|
|
||||||
err := db.CreateWorker(ctx, &w)
|
err := db.CreateWorker(ctx, &w)
|
||||||
if err != nil {
|
require.NoError(t, err, "error creating worker")
|
||||||
t.Fatalf("error creating worker: %v", err)
|
|
||||||
}
|
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
fetchedWorker, err := db.FetchWorker(ctx, w.UUID)
|
fetchedWorker, err := db.FetchWorker(ctx, w.UUID)
|
||||||
if err != nil {
|
require.NoError(t, err, "error fetching worker")
|
||||||
t.Fatalf("error fetching worker: %v", err)
|
require.NotNil(t, fetchedWorker, "fetched worker is nil, but no error returned")
|
||||||
}
|
|
||||||
if fetchedWorker == nil {
|
|
||||||
t.Fatal("fetched worker is nil, but no error returned")
|
|
||||||
}
|
|
||||||
|
|
||||||
return fetchedWorker
|
return fetchedWorker
|
||||||
}
|
}
|
||||||
|
@ -410,21 +410,15 @@ func constructTestJob(
|
|||||||
ctx context.Context, t *testing.T, db *DB, authoredJob job_compilers.AuthoredJob,
|
ctx context.Context, t *testing.T, db *DB, authoredJob job_compilers.AuthoredJob,
|
||||||
) *Job {
|
) *Job {
|
||||||
err := db.StoreAuthoredJob(ctx, authoredJob)
|
err := db.StoreAuthoredJob(ctx, authoredJob)
|
||||||
if err != nil {
|
require.NoError(t, err, "storing authored job")
|
||||||
t.Fatalf("storing authored job: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
dbJob, err := db.FetchJob(ctx, authoredJob.JobID)
|
dbJob, err := db.FetchJob(ctx, authoredJob.JobID)
|
||||||
if err != nil {
|
require.NoError(t, err, "fetching authored job")
|
||||||
t.Fatalf("fetching authored job: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Queue the job.
|
// Queue the job.
|
||||||
dbJob.Status = api.JobStatusQueued
|
dbJob.Status = api.JobStatusQueued
|
||||||
err = db.SaveJobStatus(ctx, dbJob)
|
err = db.SaveJobStatus(ctx, dbJob)
|
||||||
if err != nil {
|
require.NoError(t, err, "queueing job")
|
||||||
t.Fatalf("queueing job: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return dbJob
|
return dbJob
|
||||||
}
|
}
|
||||||
@ -457,16 +451,11 @@ func authorTestTask(name, taskType string, dependencies ...*job_compilers.Author
|
|||||||
func setTaskStatus(t *testing.T, db *DB, taskUUID string, status api.TaskStatus) {
|
func setTaskStatus(t *testing.T, db *DB, taskUUID string, status api.TaskStatus) {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
task, err := db.FetchTask(ctx, taskUUID)
|
task, err := db.FetchTask(ctx, taskUUID)
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
task.Status = status
|
task.Status = status
|
||||||
|
|
||||||
err = db.SaveTask(ctx, task)
|
require.NoError(t, db.SaveTask(ctx, task))
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func linuxWorker(t *testing.T, db *DB, updaters ...func(worker *Worker)) Worker {
|
func linuxWorker(t *testing.T, db *DB, updaters ...func(worker *Worker)) Worker {
|
||||||
@ -483,10 +472,7 @@ func linuxWorker(t *testing.T, db *DB, updaters ...func(worker *Worker)) Worker
|
|||||||
}
|
}
|
||||||
|
|
||||||
err := db.gormDB.Save(&w).Error
|
err := db.gormDB.Save(&w).Error
|
||||||
if err != nil {
|
require.NoError(t, err, "cannot save Linux worker")
|
||||||
t.Logf("cannot save Linux worker: %v", err)
|
|
||||||
t.FailNow()
|
|
||||||
}
|
|
||||||
|
|
||||||
return w
|
return w
|
||||||
}
|
}
|
||||||
@ -501,10 +487,6 @@ func windowsWorker(t *testing.T, db *DB) Worker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
err := db.gormDB.Save(&w).Error
|
err := db.gormDB.Save(&w).Error
|
||||||
if err != nil {
|
require.NoError(t, err, "cannot save Windows worker")
|
||||||
t.Logf("cannot save Windows worker: %v", err)
|
|
||||||
t.FailNow()
|
|
||||||
}
|
|
||||||
|
|
||||||
return w
|
return w
|
||||||
}
|
}
|
||||||
|
@ -267,9 +267,8 @@ func testFixtures(t *testing.T) (*SleepScheduler, TestMocks, context.Context) {
|
|||||||
|
|
||||||
mockedClock := clock.NewMock()
|
mockedClock := clock.NewMock()
|
||||||
mockedNow, err := time.Parse(time.RFC3339, "2022-06-07T11:14:47+02:00")
|
mockedNow, err := time.Parse(time.RFC3339, "2022-06-07T11:14:47+02:00")
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
mockedClock.Set(mockedNow)
|
mockedClock.Set(mockedNow)
|
||||||
if !assert.Equal(t, time.Tuesday.String(), mockedNow.Weekday().String()) {
|
if !assert.Equal(t, time.Tuesday.String(), mockedNow.Weekday().String()) {
|
||||||
t.Fatal("tests assume 'now' is a Tuesday")
|
t.Fatal("tests assume 'now' is a Tuesday")
|
||||||
|
@ -217,9 +217,7 @@ func taskLogsTestFixtures(t *testing.T) (*Storage, func(), *TaskLogsMocks) {
|
|||||||
mockCtrl := gomock.NewController(t)
|
mockCtrl := gomock.NewController(t)
|
||||||
|
|
||||||
temppath, err := ioutil.TempDir("", "testlogs")
|
temppath, err := ioutil.TempDir("", "testlogs")
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
mocks := &TaskLogsMocks{
|
mocks := &TaskLogsMocks{
|
||||||
temppath: temppath,
|
temppath: temppath,
|
||||||
@ -229,9 +227,8 @@ func taskLogsTestFixtures(t *testing.T) (*Storage, func(), *TaskLogsMocks) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
mockedNow, err := time.Parse(time.RFC3339, "2022-06-09T16:52:04+02:00")
|
mockedNow, err := time.Parse(time.RFC3339, "2022-06-09T16:52:04+02:00")
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
mocks.clock.Set(mockedNow)
|
mocks.clock.Set(mockedNow)
|
||||||
|
|
||||||
// This should be called at the end of each unit test.
|
// This should be called at the end of each unit test.
|
||||||
|
@ -11,6 +11,7 @@ import (
|
|||||||
"github.com/benbjohnson/clock"
|
"github.com/benbjohnson/clock"
|
||||||
"github.com/golang/mock/gomock"
|
"github.com/golang/mock/gomock"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"projects.blender.org/studio/flamenco/internal/manager/timeout_checker/mocks"
|
"projects.blender.org/studio/flamenco/internal/manager/timeout_checker/mocks"
|
||||||
)
|
)
|
||||||
@ -50,9 +51,7 @@ func timeoutCheckerTestFixtures(t *testing.T) (*TimeoutChecker, func(), *Timeout
|
|||||||
}
|
}
|
||||||
|
|
||||||
mockedNow, err := time.Parse(time.RFC3339, "2022-06-09T12:00:00+00:00")
|
mockedNow, err := time.Parse(time.RFC3339, "2022-06-09T12:00:00+00:00")
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
mocks.clock.Set(mockedNow)
|
mocks.clock.Set(mockedNow)
|
||||||
|
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
|
Loading…
Reference in New Issue
Block a user