@@ -5497,12 +5497,13 @@ public void testInsertRowConcurrently()
54975497 int threads = 4 ;
54985498 CyclicBarrier barrier = new CyclicBarrier (threads );
54995499 ExecutorService executor = newFixedThreadPool (threads );
5500+ long insertTimeoutMillis = getConcurrentInsertTimeout ().toMillis ();
55005501 try (TestTable table = createTableWithOneIntegerColumn ("test_insert" )) {
55015502 String tableName = table .getName ();
55025503
55035504 List <Future <OptionalInt >> futures = IntStream .range (0 , threads )
55045505 .mapToObj (threadNumber -> executor .submit (() -> {
5505- barrier .await (10 , SECONDS );
5506+ barrier .await (insertTimeoutMillis , MILLISECONDS );
55065507 try {
55075508 getQueryRunner ().execute ("INSERT INTO " + tableName + " VALUES (" + threadNumber + ")" );
55085509 return OptionalInt .of (threadNumber );
@@ -5524,7 +5525,7 @@ public void testInsertRowConcurrently()
55245525 .collect (toImmutableList ());
55255526
55265527 List <Integer > values = futures .stream ()
5527- .map (future -> tryGetFutureValue (future , 10 , SECONDS ).orElseThrow (() -> new RuntimeException ("Wait timed out" )))
5528+ .map (future -> tryGetFutureValue (future , ( int ) insertTimeoutMillis , MILLISECONDS ).orElseThrow (() -> new RuntimeException ("Wait timed out" )))
55285529 .filter (OptionalInt ::isPresent )
55295530 .map (OptionalInt ::getAsInt )
55305531 .collect (toImmutableList ());
@@ -5542,7 +5543,7 @@ public void testInsertRowConcurrently()
55425543 }
55435544 finally {
55445545 executor .shutdownNow ();
5545- executor .awaitTermination (10 , SECONDS );
5546+ executor .awaitTermination (insertTimeoutMillis , MILLISECONDS );
55465547 }
55475548 }
55485549
@@ -5552,6 +5553,14 @@ protected void verifyConcurrentInsertFailurePermissible(Exception e)
55525553 throw new AssertionError ("Unexpected concurrent insert failure" , e );
55535554 }
55545555
5556+ protected Duration getConcurrentInsertTimeout ()
5557+ {
5558+ // most often we experienced this test failing due to timeout waiting on the barrier,
5559+ // the reason behind this for pooled connectors is connection timeout,
5560+ // making this timeout adjustable according to connection timeout settings
5561+ return new Duration (10 , SECONDS );
5562+ }
5563+
55555564 // Repeat test with invocationCount for better test coverage, since the tested aspect is inherently non-deterministic.
55565565 @ RepeatedTest (4 )
55575566 @ Timeout (60 )
0 commit comments