4646
4747@ Slf4j
4848@ SpringBootTest (webEnvironment = SpringBootTest .WebEnvironment .RANDOM_PORT )
49- @ ActiveProfiles ("test " )
49+ @ ActiveProfiles ("itest " )
5050class IntegrationTests {
5151
5252 public static final String USER = "admin" ;
5353 public static final String PASSWORD = "whatever" ;
54- public static final int BLOCK_TIME_MS = 1000 ;
54+ public static final int BLOCK_TIME_MS = 5000 ;
55+ public static final int MAX_BLOCK_TO_WAIT = 3 ;
56+ public static final int POLLING_PER_BLOCK = 2 ;
57+ public static final int POLLING_INTERVAL_MS = BLOCK_TIME_MS / POLLING_PER_BLOCK ;
58+ public static final int MAX_POLLING_ATTEMPTS = MAX_BLOCK_TO_WAIT
59+ * POLLING_PER_BLOCK ;
5560
5661 @ LocalServerPort
5762 private int randomServerPort ;
@@ -83,7 +88,7 @@ public void shouldBeFinalized() throws Exception {
8388 Assertions .assertTrue (StringUtils .isNotEmpty (chainTaskId ));
8489 log .info ("Requested task initialize: {}" , chainTaskId );
8590 //should wait since returned taskID is computed, initialize is not mined yet
86- waitStatus (chainTaskId , ACTIVE , 1000 , 10 );
91+ waitStatus (chainTaskId , ACTIVE , POLLING_INTERVAL_MS , MAX_POLLING_ATTEMPTS );
8792
8893 String someBytes32Payload = TeeUtils .TEE_SCONE_ONLY_TAG ; //any would be fine
8994 String enclaveChallenge = BytesUtils .EMPTY_ADDRESS ;
@@ -98,7 +103,8 @@ public void shouldBeFinalized() throws Exception {
98103 String contributeResponseBody = appClient .requestContributeTask (chainTaskId , contributeArgs );
99104 Assertions .assertTrue (StringUtils .isNotEmpty (contributeResponseBody ));
100105 log .info ("Requested task contribute: {}" , contributeResponseBody );
101- waitStatus (chainTaskId , ChainTaskStatus .REVEALING , 1000 , 10 );
106+ waitStatus (chainTaskId , ChainTaskStatus .REVEALING , POLLING_INTERVAL_MS ,
107+ MAX_POLLING_ATTEMPTS );
102108
103109 TaskRevealArgs taskRevealArgs = new TaskRevealArgs (someBytes32Payload );
104110 String revealResponseBody = appClient .requestRevealTask (chainTaskId , taskRevealArgs );
@@ -110,7 +116,8 @@ public void shouldBeFinalized() throws Exception {
110116 String finalizeResponseBody = appClient .requestFinalizeTask (chainTaskId , taskFinalizeArgs );
111117 Assertions .assertTrue (StringUtils .isNotEmpty (finalizeResponseBody ));
112118 log .info ("Requested task finalize: {}" , finalizeResponseBody );
113- waitStatus (chainTaskId , ChainTaskStatus .COMPLETED , 1000 , 10 );
119+ waitStatus (chainTaskId , ChainTaskStatus .COMPLETED , POLLING_INTERVAL_MS ,
120+ MAX_POLLING_ATTEMPTS );
114121 }
115122
116123 @ Test
@@ -131,7 +138,8 @@ public void shouldBurstTransactionsWithAverageOfOneTxPerBlock(){
131138 try {
132139 //maximum waiting time equals nb of submitted txs
133140 //1 tx/block means N txs / N blocks
134- waitStatus (chainTaskId , ACTIVE , BLOCK_TIME_MS , taskVolume + 2 );
141+ waitStatus (chainTaskId , ACTIVE , POLLING_INTERVAL_MS ,
142+ (taskVolume + 2 ) * MAX_POLLING_ATTEMPTS );
135143 //no need to wait for propagation update in db
136144 Assertions .assertTrue (true );
137145 } catch (Exception e ) {
@@ -144,20 +152,22 @@ public void shouldBurstTransactionsWithAverageOfOneTxPerBlock(){
144152 }
145153
146154 private String triggerDeal (int taskVolume ) {
155+ int secondsPollingInterval = POLLING_INTERVAL_MS / 1000 ;
156+ int secondsTimeout = secondsPollingInterval * MAX_POLLING_ATTEMPTS ;
147157 String appAddress = iexecHubService .createApp (buildRandomName ("app" ),
148158 "docker.io/repo/name:1.0.0" ,
149159 "DOCKER" ,
150160 BytesUtils .EMPTY_HEX_STRING_32 ,
151161 "" ,
152- 30 , 1 );
162+ secondsTimeout , secondsPollingInterval );
153163 log .info ("Created app: {}" , appAddress );
154164 String workerpool = iexecHubService .createWorkerpool (buildRandomName ("pool" ),
155- 30 , 1 );
165+ secondsTimeout , secondsPollingInterval );
156166 log .info ("Created workerpool: {}" , workerpool );
157167 String datasetAddress = iexecHubService .createDataset (buildRandomName ("data" ),
158168 "https://abc.com/def.jpeg" ,
159169 BytesUtils .EMPTY_HEX_STRING_32 ,
160- 30 , 1 );
170+ secondsTimeout , secondsPollingInterval );
161171 log .info ("Created datasetAddress: {}" , datasetAddress );
162172
163173 AppOrder signedAppOrder = signerService .signAppOrder (buildAppOrder (appAddress , taskVolume ));
@@ -268,8 +278,9 @@ private RequestOrder buildRequestOrder(
268278 .build ();
269279 }
270280
281+ //TODO: Use `Awaitility` in `waitStatus` & `waitBeforeFinalizing` methods
271282 /**
272- *
283+ *
273284 * @param pollingTimeMs recommended value is block time
274285 */
275286 private void waitStatus (String chainTaskId , ChainTaskStatus statusToWait , int pollingTimeMs , int maxAttempts ) throws Exception {
@@ -300,16 +311,15 @@ private void waitBeforeFinalizing(String chainTaskId) throws Exception {
300311 ChainTask chainTask = oChainTask .get ();
301312 int winnerCounter = chainTask .getWinnerCounter ();
302313 int revealCounter = chainTask .getRevealCounter ();
303- int maxAttempts = 20 ;
304314 int attempts = 0 ;
305315 while (revealCounter != winnerCounter ) {
306316 log .info ("Waiting for reveals ({}/{})" , revealCounter , winnerCounter );
307- Thread .sleep (100 );
317+ Thread .sleep (POLLING_INTERVAL_MS );
308318 revealCounter = iexecHubService .getChainTask (chainTaskId )
309319 .map (ChainTask ::getRevealCounter )
310320 .orElse (0 );
311321 attempts ++;
312- if (attempts == maxAttempts ) {
322+ if (attempts == MAX_POLLING_ATTEMPTS ) {
313323 throw new Exception ("Too long to wait for reveal: " + chainTaskId );
314324 }
315325 }
0 commit comments