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

slawrence pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/daffodil.git

commit 490048f23bd3c1ea2f90a42631a38d01f64cf543
Author: Steve Lawrence <[email protected]>
AuthorDate: Fri Jan 27 14:31:55 2023 -0500

    Adjust socket tests to avoid time outs
    
    - Create socket producer/consumer pairs in the main thread without a
      timeout. The tests require these sockets to be created so just wait
      however long it takes. Sometimes it may take a while to create the
      sockets due to resource constraints which would lead to false
      negatives if we timed out.
    - If a particular code hunk should never time out (unless the test
      breaks), then remove the withTimeout call. This means if the test ever
      fails we might hang forever, but that is unlikely, and it's better
      than getting random false negatives and trying to determine if they
      are spurious or not
    - For tests that actually do test for a hang and require a timeout,
      adjust timeouts to be at least 1 second. This gives us more confidence
      that the test actually timed out and not that it just took too long to
      run the test
    
    DAFFODIL-2751
---
 .../daffodil/api/TestParseIndividualMessages.scala  |  5 -----
 .../org/apache/daffodil/io/SocketPairTestRig.scala  | 21 +++++++--------------
 2 files changed, 7 insertions(+), 19 deletions(-)

diff --git 
a/daffodil-core/src/test/scala/org/apache/daffodil/api/TestParseIndividualMessages.scala
 
b/daffodil-core/src/test/scala/org/apache/daffodil/api/TestParseIndividualMessages.scala
index ad1171d34..edb9cc2da 100644
--- 
a/daffodil-core/src/test/scala/org/apache/daffodil/api/TestParseIndividualMessages.scala
+++ 
b/daffodil-core/src/test/scala/org/apache/daffodil/api/TestParseIndividualMessages.scala
@@ -71,13 +71,8 @@ class TestParseIndividualMessages {
         //
         // If we need more than 4 bytes to successfully parse (we shouldn't 
for this schema)
         // then this will hang, because only 4 bytes are in fact available.
-        //
-        // Caution: if debugging, this will timeout if you stop inside here!
-        //
         val (pr: DFDL.ParseResult, xml: Node) =
-        SocketPairTestRig.withTimeout("Daffodil parse") {
           TestUtils.runDataProcessorOnInputStream(dp, cis, areTracing = false)
-        }
 
         assertFalse(pr.isError)
         assertEquals("1234", xml.text)
diff --git 
a/daffodil-io/src/test/scala/org/apache/daffodil/io/SocketPairTestRig.scala 
b/daffodil-io/src/test/scala/org/apache/daffodil/io/SocketPairTestRig.scala
index 635a8f453..890a75010 100644
--- a/daffodil-io/src/test/scala/org/apache/daffodil/io/SocketPairTestRig.scala
+++ b/daffodil-io/src/test/scala/org/apache/daffodil/io/SocketPairTestRig.scala
@@ -58,14 +58,9 @@ abstract class SocketPairTestRig {
   def run(): Unit = {
     val serverSocket = new ServerSocket(0) // 0 means to allocate an unused 
port
     val port = serverSocket.getLocalPort()
-    val csf = Future {
-      serverSocket.accept() // start accepting connections for consumer
-    }
-    val psf = Future {
-      val useLoopBack: String = null
-      new Socket(useLoopBack, port) // connect producer
-    }
-    val (producerSocket, consumerSocket) = Await.result(psf zip csf, 
1000.milliseconds)
+    val useLoopBack: String = null
+    val producerSocket = new Socket(useLoopBack, port)
+    val consumerSocket = serverSocket.accept()
     assert(producerSocket.isConnected)
     assert(consumerSocket.isConnected)
     try {
@@ -174,9 +169,7 @@ class TestSocketPairTestRig {
         //
         // read 4 bytes. Should not hang.
         //
-        // Caution: if debugging, this will timeout if you stop inside here!
-        //
-        val nRead = withTimeout("Read 4 bytes") {
+        val nRead = {
           val buf = new Array[Byte](4)
           cis.read(buf, 0, 4)
           assertEquals("1234".getBytes.toSeq, buf.toSeq)
@@ -185,7 +178,7 @@ class TestSocketPairTestRig {
         // read 1 more byte. This will hang, and timeout.
         //
         intercept[TimeoutException] {
-          withTimeout(100.milliseconds) {
+          withTimeout(1000.milliseconds) {
             val buf = new Array[Byte](1)
             cis.read(buf, 0, 1)
           }
@@ -211,7 +204,7 @@ class TestSocketPairTestRig {
         pos.flush()
 
         var buf = new Array[Byte](4)
-        var nRead = withTimeout("Read 4 bytes") {
+        var nRead = {
           //
           // This won't hang
           //
@@ -234,7 +227,7 @@ class TestSocketPairTestRig {
         // finally happens.
         //
         buf = new Array[Byte](1)
-        nRead = withTimeout {
+        nRead = {
           cis.read(buf, 0, 1)
         }
         assertEquals('4'.toByte, buf(0))

Reply via email to