Skip to content

Commit 999d118

Browse files
committed
[wip]
1 parent 867e796 commit 999d118

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

allocrunnersim/allocrunnersim.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,6 @@ func (ar *simulatedAllocRunner) Run() {
160160
}
161161
event.PopulateEventDisplayMessage()
162162
taskStates[task.Name].Events = append(taskStates[task.Name].Events, event)
163-
164163
taskStates[task.Name].StartedAt = time.Now()
165164
taskStates[task.Name].State = structs.TaskStateRunning
166165
}
@@ -213,6 +212,7 @@ func (ar *simulatedAllocRunner) clientAlloc(taskStates map[string]*structs.TaskS
213212
defer ar.allocStateLock.Unlock()
214213

215214
// store task states for AllocState to expose
215+
taskStates = maps.Clone(taskStates)
216216
ar.allocState.TaskStates = taskStates
217217

218218
a := &structs.Allocation{
@@ -345,7 +345,7 @@ func (ar *simulatedAllocRunner) stopAll() {
345345
// Ensure we have a current copy of the task states, so that we append and
346346
// create a correct and full list.
347347
ar.allocStateLock.RLock()
348-
taskStates := ar.allocState.TaskStates
348+
taskStates := ar.allocState.Copy().TaskStates
349349
ar.allocStateLock.RUnlock()
350350

351351
// Perform the task kill, which essentially is the shutdown notification.
@@ -360,8 +360,8 @@ func (ar *simulatedAllocRunner) stopAll() {
360360
event.PopulateEventDisplayMessage()
361361
taskStates[task.Name].Events = append(taskStates[task.Name].Events, event)
362362
}
363-
ar.updateAllocAndSendUpdate(taskStates)
364363

364+
ar.updateAllocAndSendUpdate(taskStates)
365365
// Mark the tasks as killed and ensure the state is updated to show they
366366
// are dead and finished.
367367
time.Sleep(200 * time.Millisecond)
@@ -375,12 +375,10 @@ func (ar *simulatedAllocRunner) stopAll() {
375375
}
376376
event.PopulateEventDisplayMessage()
377377
taskStates[task.Name].Events = append(taskStates[task.Name].Events, event)
378-
379-
ar.allocStateLock.Lock()
380-
ar.allocState.TaskStates[task.Name].FinishedAt = time.Now()
381-
ar.allocState.TaskStates[task.Name].State = structs.TaskStateDead
382-
ar.allocStateLock.Unlock()
378+
taskStates[task.Name].FinishedAt = time.Now()
379+
taskStates[task.Name].State = structs.TaskStateDead
383380
}
381+
384382
ar.updateAllocAndSendUpdate(taskStates)
385383

386384
ar.logger.Info("stopped all alloc-runner tasks and marked as complete")

0 commit comments

Comments
 (0)