Skip to content

Commit

Permalink
Merge pull request #3121 from epochcoder/fix/blocking-test-flaky
Browse files Browse the repository at this point in the history
fix: Fix flaky test (testBlockingCache) on master/pr's
  • Loading branch information
harawata committed Mar 28, 2024
2 parents e346c07 + efdb78a commit 5718c1a
Showing 1 changed file with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2009-2023 the original author or authors.
* Copyright 2009-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -18,13 +18,14 @@
import java.io.Reader;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

import org.apache.ibatis.BaseDataTest;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.jupiter.api.Assertions;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

Expand All @@ -47,7 +48,7 @@ void setUp() throws Exception {
}

@Test
void testBlockingCache() {
void testBlockingCache() throws InterruptedException {
ExecutorService defaultThreadPool = Executors.newFixedThreadPool(2);

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

defaultThreadPool.shutdown();

while (!defaultThreadPool.isTerminated()) {
continue;
if (!defaultThreadPool.awaitTermination(5, TimeUnit.SECONDS)) {
defaultThreadPool.shutdownNow();
}

long totalTime = System.currentTimeMillis() - init;
Assertions.assertTrue(totalTime > 1000);
Assertions.assertThat(totalTime).isGreaterThanOrEqualTo(1000);
}

private void accessDB() {
Expand Down

0 comments on commit 5718c1a

Please sign in to comment.