diff --git a/server/src/main/java/com/defold/extender/services/DefoldSdkService.java b/server/src/main/java/com/defold/extender/services/DefoldSdkService.java index 2ee3ce1b..cee33c3b 100644 --- a/server/src/main/java/com/defold/extender/services/DefoldSdkService.java +++ b/server/src/main/java/com/defold/extender/services/DefoldSdkService.java @@ -361,6 +361,8 @@ private JSONObject getRemotePlatformSdkMappings(String hash) throws IOException, return result; } catch (InterruptedException|ExecutionException exc) { LOGGER.error(String.format("Mappings downloading %s was interrupted", hash), exc); + } finally { + mappingsDownloadOperationCache.remove(hash); } throw new ExtenderException(String.format("Cannot find platform sdks mappings for hash: %s", hash)); } diff --git a/server/src/test/java/com/defold/extender/services/DefoldSDKServiceTest.java b/server/src/test/java/com/defold/extender/services/DefoldSDKServiceTest.java index ad4449bb..e513adfd 100644 --- a/server/src/test/java/com/defold/extender/services/DefoldSDKServiceTest.java +++ b/server/src/test/java/com/defold/extender/services/DefoldSDKServiceTest.java @@ -36,6 +36,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import static com.github.tomakehurst.wiremock.client.WireMock.*; +import static com.github.tomakehurst.wiremock.stubbing.Scenario.STARTED; public class DefoldSDKServiceTest { private static DefoldSdkServiceConfiguration configuration; @@ -108,6 +109,20 @@ public static void beforeAll() throws IOException { .withBodyFile("test_sdk_invalid.sha256") .withHeader("Content-Type", "text/plain"))); + // first call should fail; second - should be successful + stubFor(get(urlEqualTo("/unstable_sdk_mapping.json")) + .inScenario("request_chain") + .whenScenarioStateIs(STARTED) + .willReturn(aResponse() + .withStatus(404)) + .willSetStateTo("not_found")); + stubFor(get(urlEqualTo("/unstable_sdk_mapping.json")) + .inScenario("request_chain") + .whenScenarioStateIs("not_found") + .willReturn(aResponse() + .withStatus(200) + .withBody("{}") + )); } @AfterAll @@ -305,7 +320,7 @@ public void testChecksumVerification() throws IOException { DefoldSdkServiceConfiguration conf = DefoldSdkServiceConfiguration.builder() .location(Path.of("/tmp/defoldsdk")) .cacheSize(1) - .sdkUrls(new String[] {"http://localhost:8090/%s.zip"}) + .sdkUrls(new String[] {"http://localhost:" + String.valueOf(serverPort) + "/%s.zip"}) .enableSdkVerification(true) .maxVerificationRetryCount(3) .build(); @@ -318,7 +333,7 @@ public void testInvalidVerification() throws IOException { DefoldSdkServiceConfiguration disabledVerificationConf = DefoldSdkServiceConfiguration.builder() .location(Path.of("/tmp/defoldsdk")) .cacheSize(0) - .sdkUrls(new String[] {"http://localhost:8090/%s.zip"}) + .sdkUrls(new String[] {"http://localhost:" + String.valueOf(serverPort) + "/%s.zip"}) .enableSdkVerification(false) .maxVerificationRetryCount(3) .build(); @@ -328,7 +343,7 @@ public void testInvalidVerification() throws IOException { DefoldSdkServiceConfiguration enabledVerificationConf = DefoldSdkServiceConfiguration.builder() .location(Path.of("/tmp/defoldsdk")) .cacheSize(0) - .sdkUrls(new String[] {"http://localhost:8090/%s.zip"}) + .sdkUrls(new String[] {"http://localhost:" + String.valueOf(serverPort) + "/%s.zip"}) .enableSdkVerification(true) .maxVerificationRetryCount(3) .build(); @@ -341,4 +356,19 @@ public void testInvalidVerification() throws IOException { ExtenderException exc = assertThrows(ExtenderException.class, () -> sdkService1.getSdk("test_sdk_invalid")); assertTrue(exc.getMessage().contains("Sdk verification failed")); } + + @Test + public void testUnstableAccessSdkMappings() throws IOException { + DefoldSdkServiceConfiguration conf = DefoldSdkServiceConfiguration.builder() + .location(Path.of("/tmp/defoldsdk")) + .cacheSize(0) + .mappingsUrls(new String[] {"http://localhost:" + String.valueOf(serverPort) + "/%s.json"}) + .enableSdkVerification(false) + .maxVerificationRetryCount(1) + .build(); + DefoldSdkService sdkService = new DefoldSdkService(conf, new SimpleMeterRegistry()); + assertThrows(ExtenderException.class, () -> sdkService.getPlatformSdkMappings("unstable_sdk_mapping")); + + assertDoesNotThrow(() -> sdkService.getPlatformSdkMappings("unstable_sdk_mapping")); + } }