From f65fc692da59af9c5cbd391c49bafa15f5a788e8 Mon Sep 17 00:00:00 2001 From: Jeremy Bernard Date: Thu, 19 Dec 2024 14:21:23 +0100 Subject: [PATCH] Fix integration tests --- CHANGELOG.md | 2 +- .../iexec/blockchain/IntegrationTests.java | 65 +++++++++---------- 2 files changed, 33 insertions(+), 34 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 15dc28a..2b7168e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,7 @@ All notable changes to this project will be documented in this file. - Use poco-chain with poco v5.5.0 and voucher v1.0.0 in tests. (#152) - Rename `tool` package to `chain` package. (#155) -- Add tests on `TaskFinalizeService` to fix quality threshold regression. (#156) +- Add tests on `TaskFinalizeService` to fix quality threshold regression. (#156 #157) ### Dependency Upgrades diff --git a/src/itest/java/com/iexec/blockchain/IntegrationTests.java b/src/itest/java/com/iexec/blockchain/IntegrationTests.java index d09e015..6ebfea2 100644 --- a/src/itest/java/com/iexec/blockchain/IntegrationTests.java +++ b/src/itest/java/com/iexec/blockchain/IntegrationTests.java @@ -36,8 +36,6 @@ import feign.Logger; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.RandomStringUtils; -import org.apache.commons.lang3.StringUtils; -import org.awaitility.Awaitility; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -68,6 +66,7 @@ import static com.iexec.commons.poco.chain.ChainTaskStatus.ACTIVE; import static com.iexec.commons.poco.chain.ChainTaskStatus.UNSET; import static org.assertj.core.api.Assertions.assertThat; +import static org.awaitility.Awaitility.await; @Slf4j @Testcontainers @@ -90,9 +89,9 @@ class IntegrationTests { @Container static ComposeContainer environment = new ComposeContainer(new File("docker-compose.yml")) - .withPull(true) .withExposedService(CHAIN_SVC_NAME, CHAIN_SVC_PORT, Wait.forListeningPort()) - .withExposedService(MONGO_SVC_NAME, MONGO_SVC_PORT, Wait.forListeningPort()); + .withExposedService(MONGO_SVC_NAME, MONGO_SVC_PORT, Wait.forListeningPort()) + .withPull(true); @DynamicPropertySource static void registerProperties(DynamicPropertyRegistry registry) { @@ -138,18 +137,18 @@ private static String getServiceUrl(String serviceHost, int servicePort) { @Test void shouldBeFinalized() throws Exception { TransactionReceipt receipt; - String dealId = triggerDeal(1); + final String dealId = triggerDeal(1); - String chainTaskId = appClient.requestInitializeTask(dealId, 0); - Assertions.assertTrue(StringUtils.isNotEmpty(chainTaskId)); + final String chainTaskId = appClient.requestInitializeTask(dealId, 0); + assertThat(chainTaskId).isNotEmpty(); log.info("Requested task initialize: {}", chainTaskId); //should wait since returned taskID is computed, initialize is not mined yet waitStatus(chainTaskId, ACTIVE, MAX_POLLING_ATTEMPTS); - String someBytes32Payload = TeeUtils.TEE_SCONE_ONLY_TAG; //any would be fine - String enclaveChallenge = BytesUtils.EMPTY_ADDRESS; - String enclaveSignature = BytesUtils.bytesToString(new byte[65]); - WorkerpoolAuthorization workerpoolAuthorization = + final String someBytes32Payload = TeeUtils.TEE_SCONE_ONLY_TAG; //any would be fine + final String enclaveChallenge = BytesUtils.EMPTY_ADDRESS; + final String enclaveSignature = BytesUtils.bytesToString(new byte[65]); + final WorkerpoolAuthorization workerpoolAuthorization = mockAuthorization(chainTaskId, enclaveChallenge); receipt = iexecHubService.contribute( chainTaskId, @@ -165,9 +164,9 @@ void shouldBeFinalized() throws Exception { log.info("reveal {}", receipt); waitBeforeFinalizing(chainTaskId); - TaskFinalizeArgs taskFinalizeArgs = new TaskFinalizeArgs(); - String finalizeResponseBody = appClient.requestFinalizeTask(chainTaskId, taskFinalizeArgs); - Assertions.assertTrue(StringUtils.isNotEmpty(finalizeResponseBody)); + final TaskFinalizeArgs taskFinalizeArgs = new TaskFinalizeArgs("", ""); + final String finalizeResponseBody = appClient.requestFinalizeTask(chainTaskId, taskFinalizeArgs); + assertThat(finalizeResponseBody).isNotEmpty(); log.info("Requested task finalize: {}", finalizeResponseBody); waitStatus(chainTaskId, ChainTaskStatus.COMPLETED, MAX_POLLING_ATTEMPTS); @@ -176,14 +175,14 @@ void shouldBeFinalized() throws Exception { @Test void shouldBurstTransactionsWithAverageOfOneTxPerBlock() { int taskVolume = 10;//small volume ensures reasonable execution time on CI/CD - String dealId = triggerDeal(taskVolume); - List> txCompletionWatchers = new ArrayList<>(); + final String dealId = triggerDeal(taskVolume); + final List> txCompletionWatchers = new ArrayList<>(); IntStream.range(0, taskVolume) .forEach(taskIndex -> { //burst transactions (fast sequence) (send "initialize" tx examples for simplicity) String chainTaskId = appClient.requestInitializeTask(dealId, taskIndex); - Assertions.assertTrue(StringUtils.isNotEmpty(chainTaskId)); + assertThat(chainTaskId).isNotEmpty(); log.info("Requested task initialize [index:{}, chainTaskId:{}]", taskIndex, chainTaskId); //wait tx completion outside @@ -205,30 +204,30 @@ void shouldBurstTransactionsWithAverageOfOneTxPerBlock() { } private String triggerDeal(int taskVolume) { - int secondsPollingInterval = POLLING_INTERVAL_MS / 1000; - int secondsTimeout = secondsPollingInterval * MAX_POLLING_ATTEMPTS; - String appAddress = iexecHubService.createApp(buildRandomName("app"), + final int secondsPollingInterval = POLLING_INTERVAL_MS / 1000; + final int secondsTimeout = secondsPollingInterval * MAX_POLLING_ATTEMPTS; + final String appAddress = iexecHubService.createApp(buildRandomName("app"), "docker.io/repo/name:1.0.0", "DOCKER", BytesUtils.EMPTY_HEX_STRING_32, "", secondsTimeout, secondsPollingInterval); log.info("Created app: {}", appAddress); - String workerpool = iexecHubService.createWorkerpool(buildRandomName("pool"), + final String workerpool = iexecHubService.createWorkerpool(buildRandomName("pool"), secondsTimeout, secondsPollingInterval); log.info("Created workerpool: {}", workerpool); - String datasetAddress = iexecHubService.createDataset(buildRandomName("data"), + final String datasetAddress = iexecHubService.createDataset(buildRandomName("data"), "https://abc.com/def.jpeg", BytesUtils.EMPTY_HEX_STRING_32, secondsTimeout, secondsPollingInterval); log.info("Created datasetAddress: {}", datasetAddress); - OrderSigner orderSigner = new OrderSigner( + final OrderSigner orderSigner = new OrderSigner( chainConfig.getId(), chainConfig.getHubAddress(), signerService.getCredentials().getEcKeyPair()); - AppOrder signedAppOrder = orderSigner.signAppOrder(buildAppOrder(appAddress, taskVolume)); - WorkerpoolOrder signedWorkerpoolOrder = orderSigner.signWorkerpoolOrder(buildWorkerpoolOrder(workerpool, taskVolume)); - DatasetOrder signedDatasetOrder = orderSigner.signDatasetOrder(buildDatasetOrder(datasetAddress, taskVolume)); - RequestOrder signedRequestOrder = orderSigner.signRequestOrder(buildRequestOrder(signedAppOrder, + final AppOrder signedAppOrder = orderSigner.signAppOrder(buildAppOrder(appAddress, taskVolume)); + final WorkerpoolOrder signedWorkerpoolOrder = orderSigner.signWorkerpoolOrder(buildWorkerpoolOrder(workerpool, taskVolume)); + final DatasetOrder signedDatasetOrder = orderSigner.signDatasetOrder(buildDatasetOrder(datasetAddress, taskVolume)); + final RequestOrder signedRequestOrder = orderSigner.signRequestOrder(buildRequestOrder(signedAppOrder, signedWorkerpoolOrder, signedDatasetOrder, signerService.getAddress(), @@ -237,18 +236,18 @@ private String triggerDeal(int taskVolume) { .iexecResultStorageProvider("ipfs") .iexecResultStorageProxy("https://v6.result.goerli.iex.ec") .build())); - BrokerOrder brokerOrder = BrokerOrder.builder() + final BrokerOrder brokerOrder = BrokerOrder.builder() .appOrder(signedAppOrder) .workerpoolOrder(signedWorkerpoolOrder) .requestOrder(signedRequestOrder) .datasetOrder(signedDatasetOrder) .build(); - String dealId = brokerService.matchOrders(brokerOrder); - Assertions.assertTrue(StringUtils.isNotEmpty(dealId)); + final String dealId = brokerService.matchOrders(brokerOrder); + assertThat(dealId).isNotEmpty(); log.info("Created deal: {}", dealId); // no need to wait since broker is synchronous, just checking deal existence - Optional chainDeal = iexecHubService.getChainDeal(dealId); + final Optional chainDeal = iexecHubService.getChainDeal(dealId); assertThat(chainDeal).isPresent(); return dealId; } @@ -334,7 +333,7 @@ private RequestOrder buildRequestOrder( private void waitStatus(String chainTaskId, ChainTaskStatus statusToWait, int maxAttempts) { final AtomicInteger attempts = new AtomicInteger(); - Awaitility.await() + await() .pollInterval(POLLING_INTERVAL_MS, TimeUnit.MILLISECONDS) .timeout((long) maxAttempts * POLLING_INTERVAL_MS, TimeUnit.MILLISECONDS) .until(() -> { @@ -358,7 +357,7 @@ private void waitBeforeFinalizing(String chainTaskId) { log.info("{} {}", POLLING_INTERVAL_MS, MAX_POLLING_ATTEMPTS); final AtomicInteger attempts = new AtomicInteger(); - Awaitility.await() + await() .pollInterval(POLLING_INTERVAL_MS, TimeUnit.MILLISECONDS) .timeout((long) MAX_POLLING_ATTEMPTS * POLLING_INTERVAL_MS, TimeUnit.MILLISECONDS) .until(() -> {