From 629c073ed753465171e98c19765c9a9c2b8dbea4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Fri, 29 Apr 2022 12:26:53 +0200 Subject: [PATCH] Manager: fix query for job tasks --- internal/manager/persistence/jobs_query.go | 4 ++-- internal/manager/persistence/jobs_query_test.go | 15 +++++++++++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/internal/manager/persistence/jobs_query.go b/internal/manager/persistence/jobs_query.go index 314afbe1..8c5e5bbf 100644 --- a/internal/manager/persistence/jobs_query.go +++ b/internal/manager/persistence/jobs_query.go @@ -78,8 +78,8 @@ func (db *DB) QueryJobTaskSummaries(ctx context.Context, jobUUID string) ([]*Tas var result []*Task tx := db.gormDB.WithContext(ctx).Model(&Task{}). Select("tasks.id", "tasks.uuid", "tasks.name", "tasks.priority", "tasks.status", "tasks.type", "tasks.updated_at"). - Joins("left join jobs on jobs.uuid = ?", jobUUID). - // Where("jobs.uuid=?", jobUUID). + Joins("left join jobs on jobs.id = tasks.job_id"). + Where("jobs.uuid=?", jobUUID). Scan(&result) return result, tx.Error diff --git a/internal/manager/persistence/jobs_query_test.go b/internal/manager/persistence/jobs_query_test.go index 385b4d2c..16d3dff6 100644 --- a/internal/manager/persistence/jobs_query_test.go +++ b/internal/manager/persistence/jobs_query_test.go @@ -6,6 +6,7 @@ package persistence import ( "testing" + "github.com/google/uuid" "github.com/stretchr/testify/assert" "git.blender.org/flamenco/internal/manager/job_compilers" @@ -105,7 +106,7 @@ func TestQueryMetadata(t *testing.T) { assert.Equal(t, testJob.ID, result[1].ID, "status is %s", result[1].Status) } -func TestFetchJobSummary(t *testing.T) { +func TestQueryJobTaskSummaries(t *testing.T) { ctx, close, db, job, authoredJob := jobTasksTestFixtures(t) defer close() @@ -117,11 +118,21 @@ func TestFetchJobSummary(t *testing.T) { // Create another test job, just to check we get the right tasks back. otherAuthoredJob := createTestAuthoredJobWithTasks() otherAuthoredJob.Status = api.JobStatusActive - otherAuthoredJob.Tasks = []job_compilers.AuthoredTask{} + for i := range otherAuthoredJob.Tasks { + otherAuthoredJob.Tasks[i].UUID = uuid.NewString() + otherAuthoredJob.Tasks[i].Dependencies = []*job_compilers.AuthoredTask{} + } otherAuthoredJob.JobID = "138678c8-efd0-452b-ac05-397ff4c02b26" otherAuthoredJob.Metadata["project"] = "Other Project" persistAuthoredJob(t, ctx, db, otherAuthoredJob) + // Sanity check for the above code, there should be 6 tasks overall, 3 per job. + var numTasks int64 + tx := db.gormDB.Model(&Task{}).Count(&numTasks) + assert.NoError(t, tx.Error) + assert.Equal(t, int64(6), numTasks) + + // Get the task summaries of a particular job. summaries, err := db.QueryJobTaskSummaries(ctx, job.UUID) assert.NoError(t, err)