Skip to content

Commit

Permalink
fix: mark run as done when skipif is true
Browse files Browse the repository at this point in the history
  • Loading branch information
saranyailla committed Nov 23, 2024
1 parent 2554a42 commit 8629bb1
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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"));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
services:
aws.greengrass.Nucleus:
configuration:
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
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,7 @@ protected RunResult run(String name, Topics t, IntConsumer background, List<Exec
try {
if (shouldSkip(t)) {
logger.atDebug().setEventType("generic-service-skipped").addKeyValue("script", t.getFullName()).log();
return new RunResult(RunStatus.OK, null, null);
return new RunResult(RunStatus.NothingDone, null, null);
}
} catch (InputValidationException e) {
return new RunResult(RunStatus.Errored, null, ComponentStatusCode.getCodeInvalidConfigForState(name));
Expand Down

0 comments on commit 8629bb1

Please sign in to comment.