diff --git a/src/integrationtests/java/com/aws/greengrass/integrationtests/lifecyclemanager/GenericExternalServiceIntegTest.java b/src/integrationtests/java/com/aws/greengrass/integrationtests/lifecyclemanager/GenericExternalServiceIntegTest.java index 73641feed4..d6a507d6d5 100644 --- a/src/integrationtests/java/com/aws/greengrass/integrationtests/lifecyclemanager/GenericExternalServiceIntegTest.java +++ b/src/integrationtests/java/com/aws/greengrass/integrationtests/lifecyclemanager/GenericExternalServiceIntegTest.java @@ -75,6 +75,7 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import static org.junit.jupiter.api.Assumptions.assumeTrue; import static org.junit.jupiter.params.provider.Arguments.arguments; import static org.mockito.Mockito.spy; @@ -127,6 +128,64 @@ void GIVEN_service_config_with_broken_skipif_config_WHEN_launch_service_THEN_ser assertTrue(testErrored.await(10, TimeUnit.SECONDS)); } + + @Test + void GIVEN_service_config_with_skip_condition_WHEN_launch_service_THEN_skip_lifecycle() + throws Throwable { + // GIVEN + ConfigPlatformResolver.initKernelWithMultiPlatformConfig(kernel, + getClass().getResource("skipif_lifecycle" + ".yaml")); + + CountDownLatch skipLifecycles = new CountDownLatch(6); + kernel.getContext().addGlobalStateChangeListener((service, oldState, newState) -> { + try { + if (service.getName().equals("skipRun") && newState.equals(State.FINISHED)) { + skipLifecycles.countDown(); + assertFalse( + kernel.getNucleusPaths().workPath("skipRun").resolve("skipRunIndicator").toFile().exists()); + } + if (service.getName().equals("skipStartup") && newState.equals(State.FINISHED)) { + skipLifecycles.countDown(); + assertFalse( + kernel.getNucleusPaths().workPath("skipStartup").resolve("skipStartupIndicator").toFile() + .exists()); + } + if (service.getName().equals("skipInstallAndRun") && newState.equals(State.FINISHED)) { + skipLifecycles.countDown(); + assertFalse( + kernel.getNucleusPaths().workPath("skipInstallAndRun").resolve("skipInstallAndRunIndicator") + .toFile().exists()); + } + if (service.getName().equals("skipInstallAndStartup") && newState.equals(State.FINISHED)) { + skipLifecycles.countDown(); + assertFalse(kernel.getNucleusPaths().workPath("skipInstallAndStartup") + .resolve("skipInstallAndStartupIndicator").toFile().exists()); + + } + if (service.getName().equals("skipShutdown") && newState.equals(State.FINISHED)) { + skipLifecycles.countDown(); + assertTrue( + kernel.getNucleusPaths().workPath("skipShutdown").resolve("skipShutdownIndicator").toFile() + .exists()); + } + if (service.getName().equals("skipRecover") && newState.equals(State.FINISHED)) { + skipLifecycles.countDown(); + assertTrue( + kernel.getNucleusPaths().workPath("skipRecover").resolve("skipRecoveryIndicator").toFile() + .exists()); + } + } catch (IOException e) { + fail(); + } + }); + + // WHEN + kernel.launch(); + + // THEN + assertTrue(skipLifecycles.await(60, TimeUnit.SECONDS)); + } + @Test void GIVEN_service_with_timeout_WHEN_timeout_expires_THEN_move_service_to_errored() throws Exception { ConfigPlatformResolver.initKernelWithMultiPlatformConfig(kernel, getClass().getResource("service_timesout.yaml")); diff --git a/src/integrationtests/resources/com/aws/greengrass/integrationtests/lifecyclemanager/skipif_lifecycle.yaml b/src/integrationtests/resources/com/aws/greengrass/integrationtests/lifecyclemanager/skipif_lifecycle.yaml new file mode 100644 index 0000000000..284a8693a6 --- /dev/null +++ b/src/integrationtests/resources/com/aws/greengrass/integrationtests/lifecyclemanager/skipif_lifecycle.yaml @@ -0,0 +1,57 @@ +services: + aws.greengrass.Nucleus: + configuration: + runWithDefault: + posixUser: nobody + windowsUser: integ-tester + logging: + level: DEBUG + skipInstallAndRun: + lifecycle: + install: + skipif: onpath git + script: touch skipInstallAndRunIndicator + run: echo "running after skipping install" + skipInstallAndStartup: + lifecycle: + install: + skipif: onpath git + script: touch skipInstallAndStartupIndicator + startup: + script: echo "startup after skipping install" + skipStartup: + lifecycle: + startup: + skipif: onpath git + script: touch skipStartupIndicator + skipRun: + lifecycle: + run: + skipif: onpath git + script: touch skipRunIndicator + skipShutdown: + lifecycle: + install: + touch skipShutdownIndicator + shutdown: + skipif: onpath git + script: rm skipShutdownIndicator + skipRecover: + lifecycle: + install: + script: touch skipRecoveryIndicator + run: exit 1 + recovery: + skipif: onpath git + script: rm skipRecoveryIndicator + main: + lifecycle: + run: + echo "Running main" + dependencies: + - skipInstallAndRun + - skipInstallAndStartup + - skipStartup + - skipRun + - skipShutdown + - skipRecover diff --git a/src/main/java/com/aws/greengrass/lifecyclemanager/GenericExternalService.java b/src/main/java/com/aws/greengrass/lifecyclemanager/GenericExternalService.java index 928da2d39a..65a1d72e20 100644 --- a/src/main/java/com/aws/greengrass/lifecyclemanager/GenericExternalService.java +++ b/src/main/java/com/aws/greengrass/lifecyclemanager/GenericExternalService.java @@ -791,7 +791,7 @@ protected RunResult run(String name, Topics t, IntConsumer background, List