Skip to content

Commit 5718c1a

Browse files
authored
Merge pull request mybatis#3121 from epochcoder/fix/blocking-test-flaky
fix: Fix flaky test (testBlockingCache) on master/pr's
2 parents e346c07 + efdb78a commit 5718c1a

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/test/java/org/apache/ibatis/submitted/blocking_cache/BlockingCacheTest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2009-2023 the original author or authors.
2+
* Copyright 2009-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,13 +18,14 @@
1818
import java.io.Reader;
1919
import java.util.concurrent.ExecutorService;
2020
import java.util.concurrent.Executors;
21+
import java.util.concurrent.TimeUnit;
2122

2223
import org.apache.ibatis.BaseDataTest;
2324
import org.apache.ibatis.io.Resources;
2425
import org.apache.ibatis.session.SqlSession;
2526
import org.apache.ibatis.session.SqlSessionFactory;
2627
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
27-
import org.junit.jupiter.api.Assertions;
28+
import org.assertj.core.api.Assertions;
2829
import org.junit.jupiter.api.BeforeEach;
2930
import org.junit.jupiter.api.Test;
3031

@@ -47,7 +48,7 @@ void setUp() throws Exception {
4748
}
4849

4950
@Test
50-
void testBlockingCache() {
51+
void testBlockingCache() throws InterruptedException {
5152
ExecutorService defaultThreadPool = Executors.newFixedThreadPool(2);
5253

5354
long init = System.currentTimeMillis();
@@ -57,13 +58,12 @@ void testBlockingCache() {
5758
}
5859

5960
defaultThreadPool.shutdown();
60-
61-
while (!defaultThreadPool.isTerminated()) {
62-
continue;
61+
if (!defaultThreadPool.awaitTermination(5, TimeUnit.SECONDS)) {
62+
defaultThreadPool.shutdownNow();
6363
}
6464

6565
long totalTime = System.currentTimeMillis() - init;
66-
Assertions.assertTrue(totalTime > 1000);
66+
Assertions.assertThat(totalTime).isGreaterThanOrEqualTo(1000);
6767
}
6868

6969
private void accessDB() {

0 commit comments

Comments
 (0)