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

markt 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 ec897e3  Delete temporary files later to try an avoid issues with 
locked files
ec897e3 is described below

commit ec897e3daea403046a6d58a5546f112edf0d19b2
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Thu Feb 25 13:41:35 2021 +0000

    Delete temporary files later to try an avoid issues with locked files
---
 .../apache/catalina/connector/TestSendFile.java    | 47 ++++++++++------------
 .../apache/catalina/startup/LoggingBaseTest.java   |  8 ++--
 2 files changed, 26 insertions(+), 29 deletions(-)

diff --git a/test/org/apache/catalina/connector/TestSendFile.java 
b/test/org/apache/catalina/connector/TestSendFile.java
index 6392d97..09042eb 100644
--- a/test/org/apache/catalina/connector/TestSendFile.java
+++ b/test/org/apache/catalina/connector/TestSendFile.java
@@ -60,36 +60,31 @@ public class TestSendFile extends TomcatBaseTest {
         File[] files = new File[ITERATIONS];
         for (int i = 0; i < ITERATIONS; i++) {
             files[i] = generateFile(TEMP_DIR, "-" + i, EXPECTED_CONTENT_LENGTH 
* (i + 1));
+            addDeleteOnTearDown(files[i]);
         }
-        try {
 
-            for (int i = 0; i < ITERATIONS; i++) {
-                WritingServlet servlet = new WritingServlet(files[i]);
-                Tomcat.addServlet(root, "servlet" + i, servlet);
-                root.addServletMappingDecoded("/servlet" + i, "servlet" + i);
-            }
-
-            tomcat.start();
+        for (int i = 0; i < ITERATIONS; i++) {
+            WritingServlet servlet = new WritingServlet(files[i]);
+            Tomcat.addServlet(root, "servlet" + i, servlet);
+            root.addServletMappingDecoded("/servlet" + i, "servlet" + i);
+        }
 
-            ByteChunk bc = new ByteChunk();
-            Map<String, List<String>> respHeaders = new HashMap<>();
-            for (int i = 0; i < ITERATIONS; i++) {
-                long start = System.currentTimeMillis();
-                int rc = getUrl("http://localhost:"; + getPort() + "/servlet" + 
i, bc, null,
-                        respHeaders);
-                Assert.assertEquals(HttpServletResponse.SC_OK, rc);
-                System.out.println("Client received " + bc.getLength() + " 
bytes in "
-                        + (System.currentTimeMillis() - start) + " ms.");
-                Assert.assertEquals("Expected [" + EXPECTED_CONTENT_LENGTH * 
(i + 1L) +
-                        "], was [" + bc.getLength() + "]",
-                        EXPECTED_CONTENT_LENGTH * (i + 1L), bc.getLength());
+        tomcat.start();
 
-                bc.recycle();
-            }
-        } finally {
-            for (File f : files) {
-                Assert.assertTrue("Failed to clean up [" + f + "]", 
f.delete());
-            }
+        ByteChunk bc = new ByteChunk();
+        Map<String, List<String>> respHeaders = new HashMap<>();
+        for (int i = 0; i < ITERATIONS; i++) {
+            long start = System.currentTimeMillis();
+            int rc = getUrl("http://localhost:"; + getPort() + "/servlet" + i, 
bc, null,
+                    respHeaders);
+            Assert.assertEquals(HttpServletResponse.SC_OK, rc);
+            System.out.println("Client received " + bc.getLength() + " bytes 
in "
+                    + (System.currentTimeMillis() - start) + " ms.");
+            Assert.assertEquals("Expected [" + EXPECTED_CONTENT_LENGTH * (i + 
1L) +
+                    "], was [" + bc.getLength() + "]",
+                    EXPECTED_CONTENT_LENGTH * (i + 1L), bc.getLength());
+
+            bc.recycle();
         }
     }
 
diff --git a/test/org/apache/catalina/startup/LoggingBaseTest.java 
b/test/org/apache/catalina/startup/LoggingBaseTest.java
index 2e0b225..7949bbc 100644
--- a/test/org/apache/catalina/startup/LoggingBaseTest.java
+++ b/test/org/apache/catalina/startup/LoggingBaseTest.java
@@ -121,6 +121,8 @@ public abstract class LoggingBaseTest {
                 new File(System.getProperty("tomcat.test.basedir"),
                         "conf/logging.properties").toString());
 
+        // tempDir contains log files which will be open until JULI shuts down
+        deleteOnClassTearDown.add(tempDir);
     }
 
     @Before
@@ -131,13 +133,13 @@ public abstract class LoggingBaseTest {
 
     @After
     public void tearDown() throws Exception {
+        boolean deleted = true;
         for (File file : deleteOnTearDown) {
-            ExpandWar.delete(file);
+            deleted = deleted & ExpandWar.delete(file);
         }
         deleteOnTearDown.clear();
 
-        // tempDir contains log files which will be open until JULI shuts down
-        deleteOnClassTearDown.add(tempDir);
+        Assert.assertTrue("Failed to delete at least one file", deleted);
     }
 
     @AfterClass


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

Reply via email to