@@ -942,7 +942,7 @@ func TestUpdateNodeDemote(t *testing.T) {
942
942
testUpdateNodeDemote (t )
943
943
}
944
944
945
- // TestRemoveNodeAttachments tests the unexported removeNodeAttachments
945
+ // TestRemoveNodeAttachments tests the unexported orphanNodeTasks
946
946
func TestOrphanNodeTasks (t * testing.T ) {
947
947
// first, set up a store and all that
948
948
ts := newTestServer (t )
@@ -1081,7 +1081,28 @@ func TestOrphanNodeTasks(t *testing.T) {
1081
1081
},
1082
1082
},
1083
1083
}
1084
- return store .CreateTask (tx , task4 )
1084
+ if err := store .CreateTask (tx , task4 ); err != nil {
1085
+ return err
1086
+ }
1087
+
1088
+ // 5.) A regular task that's already in a terminal state on the node,
1089
+ // which does not need to be updated.
1090
+ task5 := & api.Task {
1091
+ ID : "task5" ,
1092
+ NodeID : "id2" ,
1093
+ DesiredState : api .TaskStateRunning ,
1094
+ Status : api.TaskStatus {
1095
+ // use TaskStateCompleted, as this is the earliest terminal
1096
+ // state (this ensures we don't actually use <= instead of <)
1097
+ State : api .TaskStateCompleted ,
1098
+ },
1099
+ Spec : api.TaskSpec {
1100
+ Runtime : & api.TaskSpec_Container {
1101
+ Container : & api.ContainerSpec {},
1102
+ },
1103
+ },
1104
+ }
1105
+ return store .CreateTask (tx , task5 )
1085
1106
})
1086
1107
require .NoError (t , err )
1087
1108
@@ -1096,8 +1117,7 @@ func TestOrphanNodeTasks(t *testing.T) {
1096
1117
ts .Store .View (func (tx store.ReadTx ) {
1097
1118
tasks , err := store .FindTasks (tx , store .All )
1098
1119
require .NoError (t , err )
1099
- // should only be 3 tasks left
1100
- require .Len (t , tasks , 4 )
1120
+ require .Len (t , tasks , 5 )
1101
1121
// and the list should not contain task1 or task2
1102
1122
for _ , task := range tasks {
1103
1123
require .NotNil (t , task )
0 commit comments