Skip to content

Commit

Permalink
fix: resolve bug when refreshing jobs with cross project dependency (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
arinda-arif authored May 23, 2022
1 parent dc5ab84 commit df0ca11
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
2 changes: 1 addition & 1 deletion store/postgres/job_dependency_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (repo *jobDependencyRepository) Save(ctx context.Context, projectID models.

func (repo *jobDependencyRepository) GetAll(ctx context.Context, projectID models.ProjectID) ([]models.JobIDDependenciesPair, error) {
var jobDependencies []JobDependency
if err := repo.db.WithContext(ctx).Preload("Project").Where("project_id = ?", projectID.UUID()).Find(&jobDependencies).Error; err != nil {
if err := repo.db.WithContext(ctx).Preload("DependentProject").Where("project_id = ?", projectID.UUID()).Find(&jobDependencies).Error; err != nil {
return nil, err
}

Expand Down
41 changes: 39 additions & 2 deletions store/postgres/job_dependency_repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ func TestIntegrationJobDependencyRepository(t *testing.T) {
"bucket": "gs://some_folder",
},
}
externalProjectSpec := models.ProjectSpec{
ID: models.ProjectID(uuid.New()),
Name: "t-optimus-project-2",
Config: map[string]string{
"bucket": "gs://some_folder",
},
}
hash, _ := models.NewApplicationSecret("32charshtesthashtesthashtesthash")
ctx := context.Background()

Expand All @@ -32,6 +39,7 @@ func TestIntegrationJobDependencyRepository(t *testing.T) {

projRepo := postgres.NewProjectRepository(dbConn, hash)
assert.Nil(t, projRepo.Save(ctx, projectSpec))
assert.Nil(t, projRepo.Save(ctx, externalProjectSpec))
return dbConn
}

Expand All @@ -41,6 +49,7 @@ func TestIntegrationJobDependencyRepository(t *testing.T) {
jobID1 := uuid.New()
jobID2 := uuid.New()
jobID3 := uuid.New()
jobID4 := uuid.New()
jobDependencies := []models.JobSpecDependency{
{
Job: &models.JobSpec{ID: jobID2},
Expand All @@ -52,6 +61,11 @@ func TestIntegrationJobDependencyRepository(t *testing.T) {
Project: &projectSpec,
Type: models.JobSpecDependencyTypeIntra,
},
{
Job: &models.JobSpec{ID: jobID4},
Project: &externalProjectSpec,
Type: models.JobSpecDependencyTypeInter,
},
}
repo := postgres.NewJobDependencyRepository(db)

Expand All @@ -61,11 +75,34 @@ func TestIntegrationJobDependencyRepository(t *testing.T) {
err = repo.Save(ctx, projectSpec.ID, jobID2, jobDependencies[1])
assert.Nil(t, err)

err = repo.Save(ctx, projectSpec.ID, jobID1, jobDependencies[2])
assert.Nil(t, err)

var storedJobDependencies []models.JobIDDependenciesPair
storedJobDependencies, err = repo.GetAll(ctx, projectSpec.ID)
assert.Nil(t, err)
assert.EqualValues(t, []uuid.UUID{jobID1, jobID2}, []uuid.UUID{storedJobDependencies[0].JobID, storedJobDependencies[1].JobID})
assert.EqualValues(t, []uuid.UUID{jobDependencies[0].Job.ID, jobDependencies[1].Job.ID}, []uuid.UUID{storedJobDependencies[0].DependentJobID, storedJobDependencies[1].DependentJobID})

expectedJobDependencies := []models.JobIDDependenciesPair{
{
JobID: jobID1,
DependentProject: *jobDependencies[0].Project,
DependentJobID: jobDependencies[0].Job.ID,
Type: jobDependencies[0].Type,
},
{
JobID: jobID2,
DependentProject: *jobDependencies[1].Project,
DependentJobID: jobDependencies[1].Job.ID,
Type: jobDependencies[1].Type,
},
{
JobID: jobID1,
DependentProject: *jobDependencies[2].Project,
DependentJobID: jobDependencies[2].Job.ID,
Type: jobDependencies[2].Type,
},
}
assert.EqualValues(t, expectedJobDependencies, storedJobDependencies)

err = repo.DeleteByJobID(ctx, jobID1)
assert.Nil(t, err)
Expand Down

0 comments on commit df0ca11

Please sign in to comment.