Skip to content

Commit def827d

Browse files
committed
TransactionTest: throttle unbound thread pool to limit resource consumption (especially on Windows CI)
1 parent 5bc636a commit def827d

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

tests/objectbox-java-test/src/test/java/io/objectbox/TestUtils.java

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

3434
public class TestUtils {
3535

36+
public static boolean isWindows() {
37+
final String osName = System.getProperty("os.name").toLowerCase();
38+
return osName.contains("windows");
39+
}
40+
3641
public static String loadFile(String filename) {
3742
try {
3843
InputStream in = openInputStream("/" + filename);

tests/objectbox-java-test/src/test/java/io/objectbox/TransactionTest.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import java.util.concurrent.Executors;
3030
import java.util.concurrent.Future;
3131
import java.util.concurrent.LinkedBlockingQueue;
32+
import java.util.concurrent.ThreadPoolExecutor;
3233
import java.util.concurrent.TimeUnit;
3334
import java.util.concurrent.atomic.AtomicInteger;
3435

@@ -496,7 +497,8 @@ private void runThreadPoolReaderTest(Runnable runnable) throws Exception {
496497
.noReaderThreadLocals() // This is the essential flag to make this test work
497498
.build();
498499

499-
// Unbounded thread pool so number of threads run exceeds max readers.
500+
// Unbounded (but throttled) thread pool so number of threads run exceeds max readers.
501+
int numThreads = TestUtils.isWindows() ? 300 : 1000; // Less on Windows; had some resource issues on Windows CI
500502
ExecutorService pool = Executors.newCachedThreadPool();
501503

502504
ArrayList<Future<Integer>> txTasks = new ArrayList<>(10000);
@@ -510,6 +512,9 @@ private void runThreadPoolReaderTest(Runnable runnable) throws Exception {
510512
return txNumber;
511513
}
512514
}));
515+
if (pool instanceof ThreadPoolExecutor && ((ThreadPoolExecutor) pool).getActiveCount() > numThreads) {
516+
Thread.sleep(1); // Throttle processing to limit thread resources
517+
}
513518
}
514519

515520
//Iterate through all the txTasks and make sure all transactions succeeded.

0 commit comments

Comments
 (0)