TestExecutePlanRemoveContainerDropsFromCache verifies that after a container is removed, subsequent service-reference resolution does not see its stale ID. Without this guarantee, a recreate followed by a dependent's create can pick up the just-removed container, depending on the canonical-name sort
(t *testing.T)
| 141 | // uses in production) so the test exercises the errgroup, done-channel |
| 142 | // wiring and group tracker — not a hand-rolled loop over executeNode. |
| 143 | func TestExecutePlanRemoveContainerDropsFromCache(t *testing.T) { |
| 144 | svc, apiClient := newTestService(t) |
| 145 | |
| 146 | oldCtr := container.Summary{ |
| 147 | ID: "old-id", |
| 148 | Names: []string{"/test-web-1"}, |
| 149 | Labels: map[string]string{ |
| 150 | api.ServiceLabel: "web", |
| 151 | api.ContainerNumberLabel: "1", |
| 152 | }, |
| 153 | } |
| 154 | |
| 155 | apiClient.EXPECT().ContainerStop(gomock.Any(), "old-id", gomock.Any()). |
| 156 | Return(client.ContainerStopResult{}, nil) |
| 157 | apiClient.EXPECT().ContainerRemove(gomock.Any(), "old-id", gomock.Any()). |
| 158 | Return(client.ContainerRemoveResult{}, nil) |
| 159 | |
| 160 | observed := &ObservedState{ |
| 161 | ProjectName: "test", |
| 162 | Containers: map[string][]ObservedContainer{ |
| 163 | "web": {{ID: "old-id", Summary: oldCtr}}, |
| 164 | }, |
| 165 | Networks: map[string]ObservedNetwork{}, |
| 166 | Volumes: map[string]ObservedVolume{}, |
| 167 | } |
| 168 | |
| 169 | plan := &Plan{} |
| 170 | stopNode := plan.addNode(Operation{ |
| 171 | Type: OpStopContainer, |
| 172 | ResourceID: "service:web:1", |
| 173 | Cause: "scale down", |
| 174 | Container: &oldCtr, |
| 175 | }, "") |
| 176 | plan.addNode(Operation{ |
| 177 | Type: OpRemoveContainer, |
| 178 | ResourceID: "service:web:1", |
| 179 | Cause: "scale down", |
| 180 | Container: &oldCtr, |
| 181 | }, "", stopNode) |
| 182 | |
| 183 | exec := svc.newPlanExecutor(&types.Project{Name: "test"}, observed) |
| 184 | assert.NilError(t, exec.run(t.Context(), plan)) |
| 185 | |
| 186 | assert.Equal(t, len(exec.containersByService["web"]), 0, |
| 187 | "removed container should be dropped from the live view") |
| 188 | } |
| 189 | |
| 190 | // TestExecutePlanConcurrentRemovesCacheCoherence stresses the cache mutex by |
| 191 | // scheduling N independent Stop+Remove pairs that the DAG lets the errgroup |
nothing calls this directly
no test coverage detected