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

csutherl 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 1e3ede1398 Skip APR connector tests when tomcat-native 2.x is loaded
1e3ede1398 is described below

commit 1e3ede1398435db1f9efb6280524a843c684bdf9
Author: Coty Sutherland <[email protected]>
AuthorDate: Wed Nov 11 14:51:06 2026 -0500

    Skip APR connector tests when tomcat-native 2.x is loaded
    
    tomcat-native 2 does not support the APR/native connector, but the APR test
    target only checked for the native library location before running APR 
connector
    tests. As a result, APR tests could be run against tomcat-native 2.x and 
fail
    during connector initialization.
    
    Update the APR availability check to probe tomcat-native in an APR-required
    mode and only enable APR tests when a compatible tomcat-native 1.x library 
is
    present. The existing tomcat-native availability check remains unchanged so
    non-APR native/OpenSSL tests can still run with tomcat-native 2.x.
    
    Co-authored-by: ChatGPT <[email protected]>
---
 build.xml                                         | 24 ++++++++++++++++++++---
 test/org/apache/tomcat/jni/TesterLibraryLoad.java | 13 +++++++++++-
 2 files changed, 33 insertions(+), 4 deletions(-)

diff --git a/build.xml b/build.xml
index 53d73256a6..29a2312583 100644
--- a/build.xml
+++ b/build.xml
@@ -2130,9 +2130,24 @@
               extension=".APR" />
   </target>
 
-  <target name="test-apr-exists" description="Checks for APR lib"
+  <target name="test-apr-exists" description="Checks for APR/native connector 
support"
+          depends="test-tcnative-probe-classes"
           if="${execute.test.apr}">
-    <available file="${test.apr.loc}" property="apr.exists" />
+    <junit printsummary="no" fork="yes" showoutput="false" 
haltonfailure="false"
+           failureproperty="test.apr.error" logfailedtests="false">
+      <jvmarg value="${runtests.librarypath}"/>
+      <jvmarg value="${native.nativeaccess}"/>
+      <sysproperty key="tomcat.test.apr.required" value="true"/>
+      <classpath refid="tomcat.test.classpath"/>
+      <test name="org.apache.tomcat.jni.TesterLibraryLoad"/>
+    </junit>
+
+    <condition property="apr.exists">
+      <not>
+        <isset property="test.apr.error"/>
+      </not>
+    </condition>
+    <echo message="APR/native connector support is not available. APR tests 
will be skipped." if:set="test.apr.error" level="warning"/>
   </target>
 
   <target name="test-openssl-exists" description="Checks for the OpenSSL 
binary">
@@ -2152,7 +2167,7 @@
     <echo message="OpenSSL is not available. OpenSSL-related tests will be 
skipped or may fail." level="warning" unless:set="test.openssl.exists"/>
   </target>
 
-  <target name="test-tcnative-exists" description="Verifies tomcat-native 
library can be loaded">
+  <target name="test-tcnative-probe-classes" description="Compiles classes 
used to probe tomcat-native">
     <!-- Check if main classes are built -->
     <available file="${test.run.classes}/org/apache/tomcat/jni/Library.class"
                property="tomcat.classes.available"/>
@@ -2180,7 +2195,10 @@
         <pathelement location="${junit.jar}"/>
       </classpath>
     </javac>
+  </target>
 
+  <target name="test-tcnative-exists" description="Verifies tomcat-native 
library can be loaded"
+          depends="test-tcnative-probe-classes">
     <!-- Run test - it will check both test.apr.loc and system library paths 
-->
     <junit printsummary="no" fork="yes" showoutput="false" 
haltonfailure="false"
            failureproperty="test.tcnative.error" logfailedtests="false">
diff --git a/test/org/apache/tomcat/jni/TesterLibraryLoad.java 
b/test/org/apache/tomcat/jni/TesterLibraryLoad.java
index 26ab51c91e..5baff599f8 100644
--- a/test/org/apache/tomcat/jni/TesterLibraryLoad.java
+++ b/test/org/apache/tomcat/jni/TesterLibraryLoad.java
@@ -26,12 +26,23 @@ public class TesterLibraryLoad {
 
     @Test
     public void testLibraryLoads() throws Exception {
+        boolean libraryInitialized = false;
         try {
             Library.initialize(null);
-            Library.terminate();
+            libraryInitialized = true;
+            if (Boolean.getBoolean("tomcat.test.apr.required")) {
+                Assert.assertTrue(
+                        "The APR/native connector requires Tomcat Native 1.x. 
Found Tomcat Native " +
+                                Library.versionString(),
+                        Library.TCN_MAJOR_VERSION < 2);
+            }
         } catch (LibraryNotFoundError e) {
             // Library not available - fail test to set property
             Assert.fail("Library not found");
+        } finally {
+            if (libraryInitialized) {
+                Library.terminate();
+            }
         }
     }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to