Skip to content

Commit 878639c

Browse files
authored
Merge pull request #66 from iExecBlockchainComputing/release/7.2.0
Release/7.2.0
2 parents 409a9da + 794ec84 commit 878639c

File tree

5 files changed

+34
-11
lines changed

5 files changed

+34
-11
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
All notable changes to this project will be documented in this file.
44

5+
## [[7.2.0]](https://github.com/iExecBlockchainComputing/iexec-blockchain-adapter-api/releases/tag/v7.2.0) 2023-01-09
6+
7+
* Increments jenkins-library up to version 2.2.3. Enable SonarCloud analyses on branches and pull requests.
8+
* Improve thread management in some tests.
9+
510
## [[7.1.2]](https://github.com/iExecBlockchainComputing/iexec-blockchain-adapter-api/releases/tag/v7.1.2) 2022-11-29
611

712
* Update build workflow to 2.1.4, update documentation in README and add CHANGELOG.

Jenkinsfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@Library('global-jenkins-library@2.1.4') _
1+
@Library('global-jenkins-library@2.2.3') _
22
buildJavaProject(
33
buildInfo: getBuildInfo(),
44
integrationTestsEnvVars: ['BROKER_PRIVATE_KEY'],

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version=7.1.2
1+
version=7.2.0
22
iexecCommonVersion=6.0.0
33

44
nexusUser

src/main/java/com/iexec/blockchain/tool/QueueService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ private void startAsyncActionsExecution() {
4545
* The first action is the action with the highest priority that is in the queue for the longer time.
4646
*/
4747
void executeActions() {
48-
while (Thread.currentThread().isAlive()) {
48+
while (Thread.currentThread().isAlive() && !Thread.currentThread().isInterrupted()) {
4949
executeFirstAction();
5050
}
5151
}

src/test/java/com/iexec/blockchain/tool/QueueServiceTest.java

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
import java.util.List;
1616
import java.util.Queue;
1717
import java.util.concurrent.CompletableFuture;
18+
import java.util.concurrent.ExecutorService;
19+
import java.util.concurrent.Executors;
1820
import java.util.concurrent.TimeUnit;
1921
import java.util.concurrent.atomic.AtomicBoolean;
2022
import java.util.function.Function;
@@ -24,12 +26,16 @@
2426
import static org.assertj.core.api.Assertions.assertThat;
2527

2628
class QueueServiceTest {
29+
30+
private ExecutorService executorService;
31+
2732
@InjectMocks
2833
@Spy
2934
private QueueService queueService;
3035

3136
@BeforeEach
3237
void setUp() {
38+
executorService = Executors.newSingleThreadExecutor();
3339
MockitoAnnotations.openMocks(this);
3440
}
3541

@@ -75,12 +81,15 @@ void shouldRunHighPriorityRunnable() {
7581

7682
// Start execution thread.
7783
// It won't stop itself, so we have to do it.
78-
final CompletableFuture<Void> tasksExecutionFuture = CompletableFuture.runAsync(queueService::executeActions);
84+
CompletableFuture.runAsync(queueService::executeActions, executorService);
7985
Awaitility
8086
.await()
8187
.atMost(5, TimeUnit.SECONDS)
8288
.until(() -> highPriorityTimestamps.size() == 1);
83-
tasksExecutionFuture.cancel(true);
89+
// Thread blocks indefinitely on PriorityBlockingQueue#take and needs to be interrupted
90+
// CompletableFuture#cancel does not interrupt the thread, an ExecutorService is needed
91+
// A call to ExecutorService#shutdownNow is done to interrupt the thread
92+
executorService.shutdownNow();
8493

8594
// We simply ensure the execution has completed.
8695
assertThat(highPriorityTimestamps.size()).isOne();
@@ -95,12 +104,15 @@ void shouldRunLowPriorityRunnable() {
95104

96105
// Start execution thread.
97106
// It won't stop itself, so we have to do it.
98-
final CompletableFuture<Void> tasksExecutionFuture = CompletableFuture.runAsync(queueService::executeActions);
107+
CompletableFuture.runAsync(queueService::executeActions, executorService);
99108
Awaitility
100109
.await()
101110
.atMost(5, TimeUnit.SECONDS)
102111
.until(() -> lowPriorityTimestamps.size() == 1);
103-
tasksExecutionFuture.cancel(true);
112+
// Thread blocks indefinitely on PriorityBlockingQueue#take and needs to be interrupted
113+
// CompletableFuture#cancel does not interrupt the thread, an ExecutorService is needed
114+
// A call to ExecutorService#shutdownNow is done to interrupt the thread
115+
executorService.shutdownNow();
104116

105117
// We simply ensure the execution has completed.
106118
assertThat(lowPriorityTimestamps.size()).isOne();
@@ -121,12 +133,15 @@ void shouldRunHighPriorityBeforeLowPriority() {
121133

122134
// Start execution thread.
123135
// It won't stop itself, so we have to do it.
124-
final CompletableFuture<Void> tasksExecutionFuture = CompletableFuture.runAsync(queueService::executeActions);
136+
CompletableFuture.runAsync(queueService::executeActions);
125137
Awaitility
126138
.await()
127139
.atMost(5, TimeUnit.SECONDS)
128140
.until(() -> highPriorityTimestamps.size() == 1 && lowPriorityTimestamps.size() == 1);
129-
tasksExecutionFuture.cancel(true);
141+
// Thread blocks indefinitely on PriorityBlockingQueue#take and needs to be interrupted
142+
// CompletableFuture#cancel does not interrupt the thread, an ExecutorService is needed
143+
// A call to ExecutorService#shutdownNow is done to interrupt the thread
144+
executorService.shutdownNow();
130145

131146
// We have executed a single task per priority so we that's what we should now have.
132147
assertThat(highPriorityTimestamps.size()).isOne();
@@ -177,12 +192,15 @@ void shouldExecuteInOrder() throws NoSuchFieldException {
177192

178193
// Start execution thread.
179194
// It won't stop itself, so we have to do it.
180-
final CompletableFuture<Void> executionFuture = CompletableFuture.runAsync(queueService::executeActions);
195+
CompletableFuture.runAsync(queueService::executeActions, executorService);
181196
Awaitility
182197
.await()
183198
.atMost(5, TimeUnit.SECONDS)
184199
.until(() -> executionOrder.size() == totalTasksNumber);
185-
executionFuture.cancel(true);
200+
// Thread blocks indefinitely on PriorityBlockingQueue#take and needs to be interrupted
201+
// CompletableFuture#cancel does not interrupt the thread, an ExecutorService is needed
202+
// A call to ExecutorService#shutdownNow is done to interrupt the thread
203+
executorService.shutdownNow();
186204

187205
// Tasks should have been executed in the right order.
188206
// This should look like [0, 1, 2, 3, 4, 5].

0 commit comments

Comments
 (0)