Skip to content

Commit

Permalink
fix: mark run as done when skipif is true (#1672)
Browse files Browse the repository at this point in the history
  • Loading branch information
saranyailla authored Dec 3, 2024
1 parent 2554a42 commit 1fc2633
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 2 deletions.
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,65 @@ 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(ExtensionContext context)
throws Throwable {
ignoreExceptionUltimateCauseOfType(context, TimeoutException.class);
// 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.ERRORED)) {
skipLifecycles.countDown();
assertTrue(
kernel.getNucleusPaths().workPath("skipRecover").resolve("skipRecoverIndicator").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,77 @@
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:
posix:
install:
requiresPrivilege: true
script: touch skipShutdownIndicator
shutdown:
skipif: onpath git
script: rm skipShutdownIndicator
windows:
install:
requiresPrivilege: true
script: echo NUL > skipShutdownIndicator
shutdown:
skipif: onpath git
script: del skipShutdownIndicator
skipRecover:
lifecycle:
posix:
install:
requiresPrivilege: true
script: touch skipRecoverIndicator
run: |-
exit 1
recover:
skipif: onpath git
script: rm skipRecoverIndicator
windows:
install:
requiresPrivilege: true
script: echo NUL > skipRecoverIndicator
run: powershell -command "exit 1;"
recover:
skipif: onpath git
script: del skipRecoverIndicator
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
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,8 @@ void GIVEN_endpoints_provided_WHEN_create_thing_THEN_deviceConfig_contains_provi
.parseArgs("-i", getClass().getResource("blank_config.yaml").toString(), "-r", tempRootDir.toString());
DeviceProvisioningHelper.ThingInfo thingInfo = deviceProvisioningHelper.createThing(iotClient, "TestThingPolicy", "TestThing", "mockEndpoint", "");

deviceProvisioningHelper.updateKernelConfigWithIotConfiguration(kernel, thingInfo, "us-east-1", "TestRoleAliasName", "TestCertPath");
deviceProvisioningHelper.updateKernelConfigWithIotConfiguration(kernel, thingInfo, "us-east-1",
"TestRoleAliasName", tempRootDir.resolve("TestCertPath").toString());
assertEquals("mockEndpoint", kernel.getConfig().lookup(SERVICES_NAMESPACE_TOPIC,
DEFAULT_NUCLEUS_COMPONENT_NAME, CONFIGURATION_CONFIG_KEY, DEVICE_PARAM_IOT_DATA_ENDPOINT).getOnce());
}
Expand Down

0 comments on commit 1fc2633

Please sign in to comment.