Skip to content

[orchestrator] Fix task sorting#2712

Merged
chungers merged 1 commit intomoby:masterfrom
anshulpundir:sort
Jul 26, 2018
Merged

[orchestrator] Fix task sorting#2712
chungers merged 1 commit intomoby:masterfrom
anshulpundir:sort

Conversation

@anshulpundir
Copy link
Copy Markdown
Contributor

@anshulpundir anshulpundir commented Jul 23, 2018

Typo in task sorter which causes incorrect sorting order, thus causing problems in the task reaper history cleanup logic.

@codecov
Copy link
Copy Markdown

codecov bot commented Jul 23, 2018

Codecov Report

Merging #2712 into master will increase coverage by 0.19%.
The diff coverage is 100%.

@@            Coverage Diff             @@
##           master    #2712      +/-   ##
==========================================
+ Coverage   61.69%   61.88%   +0.19%     
==========================================
  Files         134      134              
  Lines       21771    21771              
==========================================
+ Hits        13431    13473      +42     
+ Misses       6892     6840      -52     
- Partials     1448     1458      +10

Copy link
Copy Markdown
Contributor

@chungers chungers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could use an unexported function that takes a Status and returns the appropriate Timestamp. If a common function was used to extract the timestamp for either t[i].Status or t[j].Status then this copy-and-paste bug wouldn't have happened.

Thanks for adding a unit test that was sorely needed, as shown by this bug.

@thaJeztah
Copy link
Copy Markdown
Member

I see this was introduced in d489fa5 (#2332) (merged Jul 27, 2017), so likely has to be cherry-picked into all current release-branches

size := 5
seconds := int64(size)
for i := 0; i < size; i++ {
time.Sleep(1)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this sleep is not needed, because we manually set the timestamp

},
},
Status: api.TaskStatus{
Timestamp: &google_protobuf.Timestamp{},
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Timestamp.Seconds can be set directly to the desired value here;

Timestamp: &google_protobuf.Timestamp{Seconds: seconds},

},
}

task.Status.Timestamp.Seconds = seconds
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above; this doesn't look needed if it's initialised with the right value

sort.Sort(TasksByTimestamp(tasks))
expected := int64(1)
for _, task := range tasks {
timestamp := &google_protobuf.Timestamp{}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here; this can be

timestamp := &google_protobuf.Timestamp{Seconds: expected}

This would even be written as;

sort.Sort(TasksByTimestamp(tasks))
for i, task := range tasks {
	expected := &google_protobuf.Timestamp{Seconds: int64(i + 1)}
	assert.Equal(t, expected, task.Status.Timestamp)
}

Also wondering if we want to compare by the task's ID as well (or instead), e.g.;

assert.Equal(t, "id_"+strconv.Itoa(size-(i+1)), task.ID)


seconds = int64(size)
for _, task := range tasks {
task.Status.AppliedAt = &google_protobuf.Timestamp{}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

task.Status.AppliedAt = &google_protobuf.Timestamp{Seconds: seconds}

sort.Sort(TasksByTimestamp(tasks))
expected = int64(1)
for _, task := range tasks {
timestamp := &google_protobuf.Timestamp{}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above;

sort.Sort(TasksByTimestamp(tasks))
for i, task := range tasks {
	expected := &google_protobuf.Timestamp{Seconds: int64(i + 1)}
	assert.Equal(t, expected, task.Status.AppliedAt)
}

(possibly assert.Equal(t, "id_"+strconv.Itoa(i), task.ID))

time.Sleep(1)
task := &api.Task{
ID: "id_" + strconv.Itoa(i),
Spec: api.TaskSpec{
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually; looks like the Spec isn't needed for this test to work; better to remove it

@anshulpundir
Copy link
Copy Markdown
Contributor Author

We could use an unexported function that takes a Status and returns the appropriate Timestamp. If a common function was used to extract the timestamp for either t[i].Status or t[j].Status then this copy-and-paste bug wouldn't have happened.

Done.

Signed-off-by: Anshul Pundir <anshul.pundir@docker.com>
Copy link
Copy Markdown
Contributor

@chungers chungers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants