Skip to content

Commit f451eee

Browse files
authored
chore: Make integration tests tests run concurrently (#2069)
Signed-off-by: Ivan Ivanov <[email protected]>
1 parent 278a2e9 commit f451eee

File tree

3 files changed

+30
-14
lines changed

3 files changed

+30
-14
lines changed

gradle/plugins/src/main/kotlin/com.hedera.gradle.java.gradle.kts

+6
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,13 @@ tasks.withType<Javadoc>().configureEach {
7373
}
7474
}
7575

76+
tasks.withType<Test>().configureEach {
77+
failFast = true
78+
maxParallelForks = (Runtime.getRuntime().availableProcessors() / 2).coerceAtLeast(1)
79+
}
80+
7681
tasks.jacocoTestReport {
82+
dependsOn(tasks.withType<Test>())
7783
// make sure to use any/all test coverage data for the report and run all tests before this report is made
7884
executionData.from(
7985
tasks.test.map { it.extensions.getByType<JacocoTaskExtension>().destinationFile!! },

sdk/src/main/java/com/hedera/hashgraph/sdk/TransactionId.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import java.time.Duration;
2828
import java.time.Instant;
2929
import java.util.Objects;
30+
import java.util.Random;
3031
import java.util.concurrent.CompletableFuture;
3132
import java.util.concurrent.TimeoutException;
3233
import java.util.concurrent.atomic.AtomicLong;
@@ -68,6 +69,7 @@ public final class TransactionId implements Comparable<TransactionId> {
6869

6970
private static final long NANOSECONDS_TO_REMOVE = 10000000000L;
7071

72+
private static final Random randomNanosecs = new Random();
7173
private static final AtomicLong monotonicTime = new AtomicLong();
7274

7375

@@ -115,6 +117,7 @@ public static TransactionId generate(AccountId accountId) {
115117
// between the client and the receiving node and prevented spurious INVALID_TRANSACTION_START.
116118
currentTime = System.currentTimeMillis() * NANOSECONDS_PER_MILLISECOND - NANOSECONDS_TO_REMOVE;
117119

120+
118121
// Get the last recorded timestamp.
119122
lastTime = monotonicTime.get();
120123

@@ -125,7 +128,7 @@ public static TransactionId generate(AccountId accountId) {
125128
}
126129
} while (!monotonicTime.compareAndSet(lastTime, currentTime));
127130

128-
return new TransactionId(accountId, Instant.ofEpochSecond(0, currentTime));
131+
return new TransactionId(accountId, Instant.ofEpochSecond(0, currentTime + randomNanosecs.nextLong(1_000)));
129132
}
130133

131134
/**

sdk/src/testIntegration/java/com/hedera/hashgraph/sdk/test/integration/IntegrationTestEnv.java

+20-13
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
import java.util.List;
3737
import java.util.Map;
3838
import java.util.Objects;
39+
import java.util.concurrent.ExecutorService;
40+
import java.util.concurrent.Executors;
3941
import javax.annotation.Nullable;
4042
import org.junit.jupiter.api.Assumptions;
4143

@@ -48,6 +50,7 @@ public class IntegrationTestEnv implements AutoCloseable {
4850
public PublicKey operatorKey;
4951
public AccountId operatorId;
5052
public boolean isLocalNode = false;
53+
private static ExecutorService clientExecutor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
5154

5255
public IntegrationTestEnv() throws Exception {
5356
this(0);
@@ -104,7 +107,7 @@ private static Client createTestEnvClient() throws Exception {
104107
network.put(LOCAL_CONSENSUS_NODE_ENDPOINT, LOCAL_CONSENSUS_NODE_ACCOUNT_ID);
105108

106109
return Client
107-
.forNetwork(network)
110+
.forNetwork(network, clientExecutor)
108111
.setMirrorNetwork(List.of(LOCAL_MIRROR_NODE_GRPC_ENDPOINT));
109112
} else if (!System.getProperty("CONFIG_FILE").equals("")) {
110113
try {
@@ -152,19 +155,23 @@ public void assumeNotLocalNode() throws Exception {
152155
@Override
153156
public void close() throws Exception {
154157
if (!operatorId.equals(originalClient.getOperatorAccountId())) {
155-
var hbarsBalance = new AccountBalanceQuery()
156-
.setAccountId(operatorId)
157-
.execute(originalClient)
158-
.hbars;
159-
new TransferTransaction()
160-
.addHbarTransfer(operatorId, hbarsBalance.negated())
161-
.addHbarTransfer(Objects.requireNonNull(originalClient.getOperatorAccountId()), hbarsBalance)
162-
.freezeWith(originalClient)
163-
.signWithOperator(client)
164-
.execute(originalClient);
165-
client.close();
158+
try {
159+
var hbarsBalance = new AccountBalanceQuery()
160+
.setAccountId(operatorId)
161+
.execute(originalClient)
162+
.hbars;
163+
new TransferTransaction()
164+
.addHbarTransfer(operatorId, hbarsBalance.negated())
165+
.addHbarTransfer(Objects.requireNonNull(originalClient.getOperatorAccountId()), hbarsBalance)
166+
.freezeWith(originalClient)
167+
.signWithOperator(client)
168+
.execute(originalClient)
169+
.getReceipt(originalClient);
170+
171+
} catch (Exception e) {
172+
client.close();
173+
}
166174
}
167-
168175
originalClient.close();
169176
}
170177

0 commit comments

Comments
 (0)