You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by re...@apache.org on 2020/12/29 09:55:32 UTC

[tomcat] 01/02: Accurate version of the error test

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

remm pushed a commit to branch 8.5.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git

commit 4246e2cc6586dfb3fa819f94c89cd6a6db0acdbc
Author: remm <re...@apache.org>
AuthorDate: Tue Dec 29 10:47:14 2020 +0100

    Accurate version of the error test
---
 test/org/apache/catalina/realm/TestJNDIRealm.java | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/test/org/apache/catalina/realm/TestJNDIRealm.java b/test/org/apache/catalina/realm/TestJNDIRealm.java
index e6fe1f5..797f370 100644
--- a/test/org/apache/catalina/realm/TestJNDIRealm.java
+++ b/test/org/apache/catalina/realm/TestJNDIRealm.java
@@ -20,6 +20,8 @@ import java.lang.reflect.Field;
 import java.security.MessageDigest;
 import java.security.NoSuchAlgorithmException;
 import java.security.Principal;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
 
 import javax.naming.NamingEnumeration;
 import javax.naming.NamingException;
@@ -112,8 +114,6 @@ public class TestJNDIRealm {
         Assert.assertEquals(ha1(), ((GenericPrincipal)principal).getPassword());
     }
 
-    volatile int count = 0;
-
     @Test
     public void testErrorRealm() throws Exception {
         Context context = new TesterContext();
@@ -124,13 +124,12 @@ public class TestJNDIRealm {
         realm.setConnectionURL("ldap://127.0.0.1:12345");
         realm.start();
 
-        count = 0;
-        (new Thread(() -> { realm.authenticate("foo", "bar"); count++; })).start();
-        (new Thread(() -> { realm.authenticate("foo", "bar"); count++; })).start();
-        (new Thread(() -> { realm.authenticate("foo", "bar"); count++; })).start();
-        Thread.sleep(10);
+        final CountDownLatch latch = new CountDownLatch(3);
+        (new Thread(() -> { realm.authenticate("foo", "bar"); latch.countDown(); })).start();
+        (new Thread(() -> { realm.authenticate("foo", "bar"); latch.countDown(); })).start();
+        (new Thread(() -> { realm.authenticate("foo", "bar"); latch.countDown(); })).start();
 
-        Assert.assertEquals(3, count);
+        Assert.assertTrue(latch.await(30, TimeUnit.SECONDS));
     }
 
 


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org