Skip to content

Commit bf467ad

Browse files
authored
Fix integration tests (#157)
1 parent 1e07c73 commit bf467ad

File tree

2 files changed

+33
-34
lines changed

2 files changed

+33
-34
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ All notable changes to this project will be documented in this file.
88

99
- Use poco-chain with poco v5.5.0 and voucher v1.0.0 in tests. (#152)
1010
- Rename `tool` package to `chain` package. (#155)
11-
- Add tests on `TaskFinalizeService` to fix quality threshold regression. (#156)
11+
- Add tests on `TaskFinalizeService` to fix quality threshold regression. (#156 #157)
1212

1313
### Dependency Upgrades
1414

src/itest/java/com/iexec/blockchain/IntegrationTests.java

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@
3636
import feign.Logger;
3737
import lombok.extern.slf4j.Slf4j;
3838
import org.apache.commons.lang3.RandomStringUtils;
39-
import org.apache.commons.lang3.StringUtils;
40-
import org.awaitility.Awaitility;
4139
import org.junit.jupiter.api.Assertions;
4240
import org.junit.jupiter.api.BeforeEach;
4341
import org.junit.jupiter.api.Test;
@@ -68,6 +66,7 @@
6866
import static com.iexec.commons.poco.chain.ChainTaskStatus.ACTIVE;
6967
import static com.iexec.commons.poco.chain.ChainTaskStatus.UNSET;
7068
import static org.assertj.core.api.Assertions.assertThat;
69+
import static org.awaitility.Awaitility.await;
7170

7271
@Slf4j
7372
@Testcontainers
@@ -90,9 +89,9 @@ class IntegrationTests {
9089

9190
@Container
9291
static ComposeContainer environment = new ComposeContainer(new File("docker-compose.yml"))
93-
.withPull(true)
9492
.withExposedService(CHAIN_SVC_NAME, CHAIN_SVC_PORT, Wait.forListeningPort())
95-
.withExposedService(MONGO_SVC_NAME, MONGO_SVC_PORT, Wait.forListeningPort());
93+
.withExposedService(MONGO_SVC_NAME, MONGO_SVC_PORT, Wait.forListeningPort())
94+
.withPull(true);
9695

9796
@DynamicPropertySource
9897
static void registerProperties(DynamicPropertyRegistry registry) {
@@ -138,18 +137,18 @@ private static String getServiceUrl(String serviceHost, int servicePort) {
138137
@Test
139138
void shouldBeFinalized() throws Exception {
140139
TransactionReceipt receipt;
141-
String dealId = triggerDeal(1);
140+
final String dealId = triggerDeal(1);
142141

143-
String chainTaskId = appClient.requestInitializeTask(dealId, 0);
144-
Assertions.assertTrue(StringUtils.isNotEmpty(chainTaskId));
142+
final String chainTaskId = appClient.requestInitializeTask(dealId, 0);
143+
assertThat(chainTaskId).isNotEmpty();
145144
log.info("Requested task initialize: {}", chainTaskId);
146145
//should wait since returned taskID is computed, initialize is not mined yet
147146
waitStatus(chainTaskId, ACTIVE, MAX_POLLING_ATTEMPTS);
148147

149-
String someBytes32Payload = TeeUtils.TEE_SCONE_ONLY_TAG; //any would be fine
150-
String enclaveChallenge = BytesUtils.EMPTY_ADDRESS;
151-
String enclaveSignature = BytesUtils.bytesToString(new byte[65]);
152-
WorkerpoolAuthorization workerpoolAuthorization =
148+
final String someBytes32Payload = TeeUtils.TEE_SCONE_ONLY_TAG; //any would be fine
149+
final String enclaveChallenge = BytesUtils.EMPTY_ADDRESS;
150+
final String enclaveSignature = BytesUtils.bytesToString(new byte[65]);
151+
final WorkerpoolAuthorization workerpoolAuthorization =
153152
mockAuthorization(chainTaskId, enclaveChallenge);
154153
receipt = iexecHubService.contribute(
155154
chainTaskId,
@@ -165,9 +164,9 @@ void shouldBeFinalized() throws Exception {
165164
log.info("reveal {}", receipt);
166165

167166
waitBeforeFinalizing(chainTaskId);
168-
TaskFinalizeArgs taskFinalizeArgs = new TaskFinalizeArgs();
169-
String finalizeResponseBody = appClient.requestFinalizeTask(chainTaskId, taskFinalizeArgs);
170-
Assertions.assertTrue(StringUtils.isNotEmpty(finalizeResponseBody));
167+
final TaskFinalizeArgs taskFinalizeArgs = new TaskFinalizeArgs("", "");
168+
final String finalizeResponseBody = appClient.requestFinalizeTask(chainTaskId, taskFinalizeArgs);
169+
assertThat(finalizeResponseBody).isNotEmpty();
171170
log.info("Requested task finalize: {}", finalizeResponseBody);
172171
waitStatus(chainTaskId, ChainTaskStatus.COMPLETED,
173172
MAX_POLLING_ATTEMPTS);
@@ -176,14 +175,14 @@ void shouldBeFinalized() throws Exception {
176175
@Test
177176
void shouldBurstTransactionsWithAverageOfOneTxPerBlock() {
178177
int taskVolume = 10;//small volume ensures reasonable execution time on CI/CD
179-
String dealId = triggerDeal(taskVolume);
180-
List<CompletableFuture<Void>> txCompletionWatchers = new ArrayList<>();
178+
final String dealId = triggerDeal(taskVolume);
179+
final List<CompletableFuture<Void>> txCompletionWatchers = new ArrayList<>();
181180

182181
IntStream.range(0, taskVolume)
183182
.forEach(taskIndex -> {
184183
//burst transactions (fast sequence) (send "initialize" tx examples for simplicity)
185184
String chainTaskId = appClient.requestInitializeTask(dealId, taskIndex);
186-
Assertions.assertTrue(StringUtils.isNotEmpty(chainTaskId));
185+
assertThat(chainTaskId).isNotEmpty();
187186
log.info("Requested task initialize [index:{}, chainTaskId:{}]",
188187
taskIndex, chainTaskId);
189188
//wait tx completion outside
@@ -205,30 +204,30 @@ void shouldBurstTransactionsWithAverageOfOneTxPerBlock() {
205204
}
206205

207206
private String triggerDeal(int taskVolume) {
208-
int secondsPollingInterval = POLLING_INTERVAL_MS / 1000;
209-
int secondsTimeout = secondsPollingInterval * MAX_POLLING_ATTEMPTS;
210-
String appAddress = iexecHubService.createApp(buildRandomName("app"),
207+
final int secondsPollingInterval = POLLING_INTERVAL_MS / 1000;
208+
final int secondsTimeout = secondsPollingInterval * MAX_POLLING_ATTEMPTS;
209+
final String appAddress = iexecHubService.createApp(buildRandomName("app"),
211210
"docker.io/repo/name:1.0.0",
212211
"DOCKER",
213212
BytesUtils.EMPTY_HEX_STRING_32,
214213
"",
215214
secondsTimeout, secondsPollingInterval);
216215
log.info("Created app: {}", appAddress);
217-
String workerpool = iexecHubService.createWorkerpool(buildRandomName("pool"),
216+
final String workerpool = iexecHubService.createWorkerpool(buildRandomName("pool"),
218217
secondsTimeout, secondsPollingInterval);
219218
log.info("Created workerpool: {}", workerpool);
220-
String datasetAddress = iexecHubService.createDataset(buildRandomName("data"),
219+
final String datasetAddress = iexecHubService.createDataset(buildRandomName("data"),
221220
"https://abc.com/def.jpeg",
222221
BytesUtils.EMPTY_HEX_STRING_32,
223222
secondsTimeout, secondsPollingInterval);
224223
log.info("Created datasetAddress: {}", datasetAddress);
225224

226-
OrderSigner orderSigner = new OrderSigner(
225+
final OrderSigner orderSigner = new OrderSigner(
227226
chainConfig.getId(), chainConfig.getHubAddress(), signerService.getCredentials().getEcKeyPair());
228-
AppOrder signedAppOrder = orderSigner.signAppOrder(buildAppOrder(appAddress, taskVolume));
229-
WorkerpoolOrder signedWorkerpoolOrder = orderSigner.signWorkerpoolOrder(buildWorkerpoolOrder(workerpool, taskVolume));
230-
DatasetOrder signedDatasetOrder = orderSigner.signDatasetOrder(buildDatasetOrder(datasetAddress, taskVolume));
231-
RequestOrder signedRequestOrder = orderSigner.signRequestOrder(buildRequestOrder(signedAppOrder,
227+
final AppOrder signedAppOrder = orderSigner.signAppOrder(buildAppOrder(appAddress, taskVolume));
228+
final WorkerpoolOrder signedWorkerpoolOrder = orderSigner.signWorkerpoolOrder(buildWorkerpoolOrder(workerpool, taskVolume));
229+
final DatasetOrder signedDatasetOrder = orderSigner.signDatasetOrder(buildDatasetOrder(datasetAddress, taskVolume));
230+
final RequestOrder signedRequestOrder = orderSigner.signRequestOrder(buildRequestOrder(signedAppOrder,
232231
signedWorkerpoolOrder,
233232
signedDatasetOrder,
234233
signerService.getAddress(),
@@ -237,18 +236,18 @@ private String triggerDeal(int taskVolume) {
237236
.iexecResultStorageProvider("ipfs")
238237
.iexecResultStorageProxy("https://v6.result.goerli.iex.ec")
239238
.build()));
240-
BrokerOrder brokerOrder = BrokerOrder.builder()
239+
final BrokerOrder brokerOrder = BrokerOrder.builder()
241240
.appOrder(signedAppOrder)
242241
.workerpoolOrder(signedWorkerpoolOrder)
243242
.requestOrder(signedRequestOrder)
244243
.datasetOrder(signedDatasetOrder)
245244
.build();
246245

247-
String dealId = brokerService.matchOrders(brokerOrder);
248-
Assertions.assertTrue(StringUtils.isNotEmpty(dealId));
246+
final String dealId = brokerService.matchOrders(brokerOrder);
247+
assertThat(dealId).isNotEmpty();
249248
log.info("Created deal: {}", dealId);
250249
// no need to wait since broker is synchronous, just checking deal existence
251-
Optional<ChainDeal> chainDeal = iexecHubService.getChainDeal(dealId);
250+
final Optional<ChainDeal> chainDeal = iexecHubService.getChainDeal(dealId);
252251
assertThat(chainDeal).isPresent();
253252
return dealId;
254253
}
@@ -334,7 +333,7 @@ private RequestOrder buildRequestOrder(
334333

335334
private void waitStatus(String chainTaskId, ChainTaskStatus statusToWait, int maxAttempts) {
336335
final AtomicInteger attempts = new AtomicInteger();
337-
Awaitility.await()
336+
await()
338337
.pollInterval(POLLING_INTERVAL_MS, TimeUnit.MILLISECONDS)
339338
.timeout((long) maxAttempts * POLLING_INTERVAL_MS, TimeUnit.MILLISECONDS)
340339
.until(() -> {
@@ -358,7 +357,7 @@ private void waitBeforeFinalizing(String chainTaskId) {
358357
log.info("{} {}", POLLING_INTERVAL_MS, MAX_POLLING_ATTEMPTS);
359358

360359
final AtomicInteger attempts = new AtomicInteger();
361-
Awaitility.await()
360+
await()
362361
.pollInterval(POLLING_INTERVAL_MS, TimeUnit.MILLISECONDS)
363362
.timeout((long) MAX_POLLING_ATTEMPTS * POLLING_INTERVAL_MS, TimeUnit.MILLISECONDS)
364363
.until(() -> {

0 commit comments

Comments
 (0)