From 38fe8dae75cd05bf313626b968e208dcfb6f307c Mon Sep 17 00:00:00 2001 From: Christina Ying Wang Date: Thu, 22 Jun 2023 12:45:59 -0700 Subject: [PATCH] Remove the 'Stopped' status for services It's not an official status from container inspects, and the Supervisor doesn't set it internally anywhere. It's better to remove it entirely as the method by which Supervisor sets internal service statuses is by using a global event emitter (reportNewStatus) which makes things difficult to test. Change-type: patch Signed-off-by: Christina Ying Wang --- src/compose/app.ts | 2 +- src/compose/service.ts | 1 - test/integration/compose/application-manager.spec.ts | 6 +++--- test/integration/device-api/actions.spec.ts | 12 ++++++------ 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/compose/app.ts b/src/compose/app.ts index cfb3b7b1..43aa7671 100644 --- a/src/compose/app.ts +++ b/src/compose/app.ts @@ -403,7 +403,7 @@ export class App { // check that we want to stop it, and that it isn't stopped return ( serviceTarget.config.running === false && - serviceCurrent.status !== 'Stopped' + serviceCurrent.status !== 'exited' ); }; diff --git a/src/compose/service.ts b/src/compose/service.ts index 0e2207e2..e93e4c99 100644 --- a/src/compose/service.ts +++ b/src/compose/service.ts @@ -40,7 +40,6 @@ const unsupportedSecurityOpt = (opt: string) => /label=.*/.test(opt); export type ServiceStatus = | 'Stopping' - | 'Stopped' | 'Running' | 'Installing' | 'Installed' diff --git a/test/integration/compose/application-manager.spec.ts b/test/integration/compose/application-manager.spec.ts index 3c7c38fe..7683a004 100644 --- a/test/integration/compose/application-manager.spec.ts +++ b/test/integration/compose/application-manager.spec.ts @@ -1309,7 +1309,7 @@ describe('compose/application-manager', () => { { commit: 'oldrelease', serviceName: 'fedora', - status: 'Stopped', + status: 'exited', createdAt: new Date('2021-09-01T12:00:00'), }, { @@ -1317,7 +1317,7 @@ describe('compose/application-manager', () => { appUuid: 'debian', commit: 'otherrelease', serviceName: 'debian', - status: 'Stopped', + status: 'exited', createdAt: new Date('2021-09-01T12:00:00'), }, ]); @@ -1351,7 +1351,7 @@ describe('compose/application-manager', () => { services: { fedora: { image: 'fedora:older', - status: 'Stopped', + status: 'exited', }, }, }, diff --git a/test/integration/device-api/actions.spec.ts b/test/integration/device-api/actions.spec.ts index bef070e5..21469575 100644 --- a/test/integration/device-api/actions.spec.ts +++ b/test/integration/device-api/actions.spec.ts @@ -137,10 +137,10 @@ describe('manages application lifecycle', () => { const isAllRunning = (ctns: Docker.ContainerInspectInfo[]) => ctns.every((ctn) => ctn.State.Running); - const isAllStopped = (ctns: Docker.ContainerInspectInfo[]) => + const isAllExited = (ctns: Docker.ContainerInspectInfo[]) => ctns.every((ctn) => !ctn.State.Running); - const isSomeStopped = (ctns: Docker.ContainerInspectInfo[]) => + const isSomeExited = (ctns: Docker.ContainerInspectInfo[]) => ctns.some((ctn) => !ctn.State.Running); // Wait until containers are in a ready state prior to testing assertions @@ -296,11 +296,11 @@ describe('manages application lifecycle', () => { .post('/v1/apps/1/stop') .set('Content-Type', 'application/json'); - const stoppedContainers = await waitForSetup(targetState, isAllStopped); + const stoppedContainers = await waitForSetup(targetState, isAllExited); // Technically the wait function above should already verify that the two // containers have been restarted, but verify explcitly with an assertion - expect(isAllStopped(stoppedContainers)).to.be.true; + expect(isAllExited(stoppedContainers)).to.be.true; // Containers should have the same Ids since none should be removed expect(stoppedContainers.map(({ Id }) => Id)).to.have.members( @@ -577,11 +577,11 @@ describe('manages application lifecycle', () => { .set('Content-Type', 'application/json') .send(JSON.stringify({ serviceName: serviceNames[0] })); - const stoppedContainers = await waitForSetup(targetState, isSomeStopped); + const stoppedContainers = await waitForSetup(targetState, isSomeExited); // Technically the wait function above should already verify that the two // containers have been restarted, but verify explcitly with an assertion - expect(isSomeStopped(stoppedContainers)).to.be.true; + expect(isSomeExited(stoppedContainers)).to.be.true; // Containers should have the same Ids since none should be removed expect(stoppedContainers.map(({ Id }) => Id)).to.have.members(