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 |
chungers
left a comment
There was a problem hiding this comment.
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.
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.
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.
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.
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.
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.
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.
Actually; looks like the Spec isn't needed for this test to work; better to remove it
Done. |
Signed-off-by: Anshul Pundir <anshul.pundir@docker.com>
Typo in task sorter which causes incorrect sorting order, thus causing problems in the task reaper history cleanup logic.