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:51:46 UTC

[tomcat] branch 9.0.x updated: Accurate version of the error test

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

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


The following commit(s) were added to refs/heads/9.0.x by this push:
     new c906bea  Accurate version of the error test
c906bea is described below

commit c906bea693e56fd517b695704c88f1f5271fc553
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 62a7495..bbe471e 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