You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by sr...@apache.org on 2023/02/13 08:27:00 UTC

[plc4x] branch develop updated: fix(plc4j/connection-cache): fix issue with timing of thread during double connection test. (#796)

This is an automated email from the ASF dual-hosted git repository.

sruehl pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git


The following commit(s) were added to refs/heads/develop by this push:
     new b58ae5dac5 fix(plc4j/connection-cache): fix issue with timing of thread during double connection test. (#796)
b58ae5dac5 is described below

commit b58ae5dac53ac99cf3827beab2f81c859e83df36
Author: Ben Hutcheson <be...@gmail.com>
AuthorDate: Mon Feb 13 09:26:55 2023 +0100

    fix(plc4j/connection-cache): fix issue with timing of thread during double connection test. (#796)
---
 .../plc4x/java/utils/cache/CachedPlcConnectionManagerTest.java | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/plc4j/tools/connection-cache/src/test/java/org/apache/plc4x/java/utils/cache/CachedPlcConnectionManagerTest.java b/plc4j/tools/connection-cache/src/test/java/org/apache/plc4x/java/utils/cache/CachedPlcConnectionManagerTest.java
index d638195bad..e8fc53a3e0 100644
--- a/plc4j/tools/connection-cache/src/test/java/org/apache/plc4x/java/utils/cache/CachedPlcConnectionManagerTest.java
+++ b/plc4j/tools/connection-cache/src/test/java/org/apache/plc4x/java/utils/cache/CachedPlcConnectionManagerTest.java
@@ -27,6 +27,7 @@ import org.junit.jupiter.api.Test;
 import org.mockito.Mockito;
 
 import java.time.Duration;
+import java.util.concurrent.CountDownLatch;
 
 public class CachedPlcConnectionManagerTest {
 
@@ -121,20 +122,21 @@ public class CachedPlcConnectionManagerTest {
         // Create a connectionManager with a maximum wait time of 50ms
         PlcConnectionManager mockConnectionManager = Mockito.mock(PlcConnectionManager.class);
         CachedPlcConnectionManager connectionManager = CachedPlcConnectionManager.getBuilder(mockConnectionManager).withMaxWaitTime(Duration.ofMillis(50)).build();
+        CountDownLatch startSignal = new CountDownLatch(1);
 
         // Get the connection for the first time.
         (new Thread(() -> {
-            try (PlcConnection connection = connectionManager.getConnection("test")) {
+            try {
+                PlcConnection connection = connectionManager.getConnection("test");
+                startSignal.countDown();
                 Assertions.assertInstanceOf(LeasedPlcConnection.class, connection);
-                // Sleep for a second.
-                Thread.sleep(100L);
             } catch (Exception e) {
                 Assertions.fail("Not expecting an exception here", e);
             }
         })).start();
 
         // This is needed as starting the previous thread seems to take a little-bit of time.
-        Thread.sleep(10L);
+        startSignal.await();
 
         // Get the same connection a second time.
         try (PlcConnection ignored = connectionManager.getConnection("test")) {