-
Notifications
You must be signed in to change notification settings - Fork 129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DEVPROD-10103 Account for cross-build dependents in NumDependents #8560
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -979,6 +979,8 @@ func createVersionItems(ctx context.Context, v *model.Version, metadata model.Ve | |
}, | ||
}) | ||
} | ||
// We must set the NumDependents field for tasks prior to inserting them in the DB. | ||
model.SetNumDependents(tasksToCreate) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And here? This is just for my curiosity but if the reason is involved enough, it might be worth adding a comment since it doesn't seem to affect the adjacent logic There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same rationale as the other comment |
||
|
||
grip.ErrorWhen(len(buildsToCreate) == 0, message.Fields{ | ||
"message": "version has no builds", | ||
|
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -84,7 +84,6 @@ func TestStoreRepositoryRevisions(t *testing.T) { | |||||||
So(err, ShouldBeNil) | ||||||||
repoTracker := RepoTracker{testConfig, evgProjectRef, NewGithubRepositoryPoller(evgProjectRef)} | ||||||||
|
||||||||
// insert distros used in testing. | ||||||||
d := distro.Distro{Id: "test-distro-one"} | ||||||||
So(d.Insert(ctx), ShouldBeNil) | ||||||||
d.Id = "test-distro-two" | ||||||||
|
@@ -191,7 +190,6 @@ func TestStoreRepositoryRevisions(t *testing.T) { | |||||||
poller, | ||||||||
} | ||||||||
|
||||||||
// insert distros used in testing. | ||||||||
d := distro.Distro{Id: "test-distro-one"} | ||||||||
So(d.Insert(ctx), ShouldBeNil) | ||||||||
d.Id = "test-distro-two" | ||||||||
|
@@ -274,6 +272,113 @@ func TestStoreRepositoryRevisions(t *testing.T) { | |||||||
}) | ||||||||
} | ||||||||
|
||||||||
func TestCountNumDependentsAcrossVariants(t *testing.T) { | ||||||||
ctx, cancel := context.WithCancel(context.Background()) | ||||||||
defer cancel() | ||||||||
require.NoError(t, db.ClearCollections(model.VersionCollection, distro.Collection, model.ParserProjectCollection, | ||||||||
build.Collection, task.Collection, model.ProjectConfigCollection, model.ProjectRefCollection)) | ||||||||
|
||||||||
simpleYml := ` | ||||||||
buildvariants: | ||||||||
- name: bv1 | ||||||||
display_name: "bv_display" | ||||||||
run_on: d1 | ||||||||
tasks: | ||||||||
- name: t1 | ||||||||
- name: t2 | ||||||||
- name: t3 | ||||||||
- name: t4 | ||||||||
- name: bv2 | ||||||||
display_name: bv2_display | ||||||||
run_on: d2 | ||||||||
tasks: | ||||||||
- name: t1 | ||||||||
- name: bv3 | ||||||||
display_name: bv3_display | ||||||||
run_on: d2 | ||||||||
tasks: | ||||||||
- name: t4 | ||||||||
depends_on: | ||||||||
- name: t1 | ||||||||
variant: bv1 | ||||||||
tasks: | ||||||||
- name: t1 | ||||||||
- name: t2 | ||||||||
depends_on: | ||||||||
- name: t1 | ||||||||
- name: t3 | ||||||||
depends_on: | ||||||||
- name: t1 | ||||||||
- name: t4 | ||||||||
depends_on: | ||||||||
- name: t2 | ||||||||
- name: t3 | ||||||||
` | ||||||||
previouslyActivatedVersion := &model.Version{ | ||||||||
Id: "previously activated", | ||||||||
Identifier: "testproject", | ||||||||
Requester: evergreen.RepotrackerVersionRequester, | ||||||||
BuildVariants: []model.VersionBuildStatus{ | ||||||||
{ | ||||||||
BuildVariant: "bv1", | ||||||||
BatchTimeTasks: []model.BatchTimeTaskStatus{ | ||||||||
{ | ||||||||
TaskName: "t1", | ||||||||
ActivationStatus: model.ActivationStatus{ | ||||||||
Activated: true, | ||||||||
ActivateAt: time.Now().Add(-11 * time.Minute), | ||||||||
}, | ||||||||
}, | ||||||||
}, | ||||||||
ActivationStatus: model.ActivationStatus{ | ||||||||
Activated: true, | ||||||||
ActivateAt: time.Now().Add(-11 * time.Minute), | ||||||||
}, | ||||||||
}, | ||||||||
{ | ||||||||
BuildVariant: "bv2", | ||||||||
ActivationStatus: model.ActivationStatus{ | ||||||||
Activated: true, | ||||||||
ActivateAt: time.Now().Add(-11 * time.Minute), | ||||||||
}, | ||||||||
}, | ||||||||
}, | ||||||||
} | ||||||||
require.NoError(t, previouslyActivatedVersion.Insert()) | ||||||||
|
||||||||
d := distro.Distro{Id: "d1"} | ||||||||
require.NoError(t, d.Insert(ctx)) | ||||||||
d.Id = "d2" | ||||||||
require.NoError(t, d.Insert(ctx)) | ||||||||
|
||||||||
pRef := &model.ProjectRef{ | ||||||||
Id: "testproject", | ||||||||
BatchTime: 0, | ||||||||
} | ||||||||
require.NoError(t, pRef.Insert()) | ||||||||
|
||||||||
p := &model.Project{} | ||||||||
pp, err := model.LoadProjectInto(ctx, []byte(simpleYml), nil, "testproject", p) | ||||||||
assert.NoError(t, err) | ||||||||
require.NotNil(t, pp) | ||||||||
|
||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Looking at |
||||||||
// Create new version to use for activating | ||||||||
revisions := []model.Revision{ | ||||||||
*createTestRevision("yes", time.Now()), | ||||||||
} | ||||||||
repoTracker := RepoTracker{ | ||||||||
testConfig, | ||||||||
pRef, | ||||||||
NewMockRepoPoller(pp, revisions), | ||||||||
} | ||||||||
assert.NoError(t, repoTracker.StoreRevisions(ctx, revisions)) | ||||||||
|
||||||||
bv1t1, err := task.FindOne(db.Query(bson.M{task.BuildVariantKey: "bv1", task.DisplayNameKey: "t1"})) | ||||||||
require.NoError(t, err) | ||||||||
require.NotNil(t, bv1t1) | ||||||||
assert.Equal(t, bv1t1.NumDependents, 4) | ||||||||
} | ||||||||
|
||||||||
func TestBatchTimeForTasks(t *testing.T) { | ||||||||
ctx, cancel := context.WithCancel(context.Background()) | ||||||||
defer cancel() | ||||||||
|
@@ -345,7 +450,6 @@ tasks: | |||||||
} | ||||||||
assert.NoError(t, previouslyActivatedVersion.Insert()) | ||||||||
|
||||||||
// insert distros used in testing. | ||||||||
d := distro.Distro{Id: "d1"} | ||||||||
assert.NoError(t, d.Insert(ctx)) | ||||||||
d.Id = "d2" | ||||||||
|
@@ -361,7 +465,7 @@ tasks: | |||||||
pp, err := model.LoadProjectInto(ctx, []byte(simpleYml), nil, "testproject", p) | ||||||||
assert.NoError(t, err) | ||||||||
|
||||||||
// create new version to use for activating | ||||||||
// Create new version to use for activating | ||||||||
revisions := []model.Revision{ | ||||||||
*createTestRevision("yes", time.Now()), | ||||||||
} | ||||||||
|
@@ -479,7 +583,6 @@ func TestBatchTimes(t *testing.T) { | |||||||
|
||||||||
So(previouslyActivatedVersion.Insert(), ShouldBeNil) | ||||||||
|
||||||||
// insert distros used in testing. | ||||||||
d := distro.Distro{Id: "test-distro-one"} | ||||||||
So(d.Insert(ctx), ShouldBeNil) | ||||||||
d.Id = "test-distro-two" | ||||||||
|
@@ -645,7 +748,6 @@ func TestBatchTimes(t *testing.T) { | |||||||
Requester: evergreen.RepotrackerVersionRequester, | ||||||||
} | ||||||||
So(previouslyActivatedVersion.Insert(), ShouldBeNil) | ||||||||
// insert distros used in testing. | ||||||||
d := distro.Distro{Id: "test-distro-one"} | ||||||||
So(d.Insert(ctx), ShouldBeNil) | ||||||||
d.Id = "test-distro-two" | ||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we call this here now too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because the
CreateBuildFromVersionNoInsert
calls that occur inside the loop no longer set the tasks num dependents field, we now need to do it right before we insert all tasks for the version