From 400a1427b9a0680f82e4d2992c6ae5ca675790b3 Mon Sep 17 00:00:00 2001 From: Don Brutzman <brutzman@nps.edu> Date: Sun, 4 Jul 2021 12:39:59 -0700 Subject: [PATCH] improved diagnostic outputs --- test/edu/nps/moves/dis7/PduTest.java | 34 +++++++++++++++++++++------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/test/edu/nps/moves/dis7/PduTest.java b/test/edu/nps/moves/dis7/PduTest.java index dd27c3f967..d0a49a3876 100644 --- a/test/edu/nps/moves/dis7/PduTest.java +++ b/test/edu/nps/moves/dis7/PduTest.java @@ -50,9 +50,13 @@ import org.junit.jupiter.api.BeforeEach; abstract public class PduTest { - protected final long THREAD_SLEEP_INTERVAL_MSEC_DEFAULT = 100l; // i.e. 100, type long + protected final long THREAD_SLEEP_INTERVAL_MSEC_DEFAULT = 1000l; // e.g. 100 msec, type long private long threadSleepInterval = THREAD_SLEEP_INTERVAL_MSEC_DEFAULT; private int maximumRetryAttempts = 10; + + Pdu receivedPdu; + DisThreadedNetworkInterface disNetworkInterface; + DisThreadedNetworkInterface.PduListener pduListener; @BeforeAll public static void setUpClass() @@ -65,10 +69,6 @@ abstract public class PduTest { } - DisThreadedNetworkInterface disNetworkInterface; - Pdu receivedPdu; - DisThreadedNetworkInterface.PduListener pduListener; - /** Ensure network connections, listener and handler are prepared */ @BeforeEach public void setUp() @@ -92,6 +92,16 @@ abstract public class PduTest disNetworkInterface.removeListener(pduListener); disNetworkInterface.kill(); disNetworkInterface = null; + try // additional sleep, allowing teardown to proceed + { + Thread.sleep(getThreadSleepInterval()); + } + catch (InterruptedException ie) + { + System.err.flush(); + System.err.println ("*** tearDown() failed to sleep"); + ie.printStackTrace(); + } } /** @@ -113,10 +123,18 @@ abstract public class PduTest Thread.sleep(getThreadSleepInterval()); if (receivedPdu != null) return; + // no receipt yet numberOfReadTests++; - System.out.flush(); + String padding1 = new String(); // count + String padding2 = new String(); // duration + if (numberOfReadTests < 10) + padding1 = " "; + if ((numberOfReadTests * getThreadSleepInterval()) < 1000l) + padding2 = " "; System.err.println ("*** PduTest.sendIeeeStandardPdu(" + createdPdu.getPduType().name() + ")" + - " receipt reattempt #" + numberOfReadTests + ", " + (numberOfReadTests * getThreadSleepInterval()) + " msec total"); + " receipt reattempt " + padding1 + "#" + numberOfReadTests + ", " + padding2 + + (numberOfReadTests * getThreadSleepInterval()) + " msec total sleep"); + System.err.flush(); } while (numberOfReadTests < getMaximumRetryAttempts()); System.err.println ("*** PduTest.sendIeeeStandardPdu(" + createdPdu.getPduType().name() + ") did not succeed"); @@ -156,7 +174,7 @@ abstract public class PduTest */ protected void testPduSendReceiveHeaderMatch (Pdu createdPdu) { - String TEST_SUITE_WARNING = " (TODO note that test works standalone but mysteriously fails as part of project test suite)"; + String TEST_SUITE_WARNING = " (TODO note that test may work standalone but mysteriously fail as part of project test suite)"; sendIeeeStandardPdu(createdPdu); // send to self, then wait a while, then return receivedPdu assertTrue(receivedPdu != null, "No response from network receive after " + -- GitLab