-
Notifications
You must be signed in to change notification settings - Fork 615
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
[orchestrator] Fix task sorting #2712
Conversation
Codecov Report
@@ 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 |
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.
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.
manager/orchestrator/task_test.go
Outdated
size := 5 | ||
seconds := int64(size) | ||
for i := 0; i < size; i++ { | ||
time.Sleep(1) |
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.
Looks like this sleep is not needed, because we manually set the timestamp
manager/orchestrator/task_test.go
Outdated
}, | ||
}, | ||
Status: api.TaskStatus{ | ||
Timestamp: &google_protobuf.Timestamp{}, |
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.
Timestamp.Seconds can be set directly to the desired value here;
Timestamp: &google_protobuf.Timestamp{Seconds: seconds},
manager/orchestrator/task_test.go
Outdated
}, | ||
} | ||
|
||
task.Status.Timestamp.Seconds = seconds |
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.
See above; this doesn't look needed if it's initialised with the right value
manager/orchestrator/task_test.go
Outdated
sort.Sort(TasksByTimestamp(tasks)) | ||
expected := int64(1) | ||
for _, task := range tasks { | ||
timestamp := &google_protobuf.Timestamp{} |
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.
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)
manager/orchestrator/task_test.go
Outdated
|
||
seconds = int64(size) | ||
for _, task := range tasks { | ||
task.Status.AppliedAt = &google_protobuf.Timestamp{} |
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.
task.Status.AppliedAt = &google_protobuf.Timestamp{Seconds: seconds}
manager/orchestrator/task_test.go
Outdated
sort.Sort(TasksByTimestamp(tasks)) | ||
expected = int64(1) | ||
for _, task := range tasks { | ||
timestamp := &google_protobuf.Timestamp{} |
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.
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)
)
manager/orchestrator/task_test.go
Outdated
time.Sleep(1) | ||
task := &api.Task{ | ||
ID: "id_" + strconv.Itoa(i), | ||
Spec: api.TaskSpec{ |
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.
Actually; looks like the Spec
isn't needed for this test to work; better to remove it
Done. |
Signed-off-by: Anshul Pundir <[email protected]>
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.
LGTM
Typo in task sorter which causes incorrect sorting order, thus causing problems in the task reaper history cleanup logic.