diff options
author | Michael P. Soulier <msoulier@digitaltorque.ca> | 2022-04-18 10:11:58 -0400 |
---|---|---|
committer | Michael P. Soulier <msoulier@digitaltorque.ca> | 2022-04-18 10:11:58 -0400 |
commit | 57feb2c3416c59d6c0a2061d7bc2e56bc7c87ad5 (patch) | |
tree | 43d59e3dd604566cba177d1b8fc871f890b3d876 | |
parent | 5ee2341be8330397aa39d14d71439aea5b9264a6 (diff) | |
download | tftpy-57feb2c3416c59d6c0a2061d7bc2e56bc7c87ad5.tar.gz |
Updated unreliable network test case.
-rw-r--r-- | t/test.py | 44 | ||||
-rw-r--r-- | tftpy/TftpContexts.py | 1 |
2 files changed, 40 insertions, 5 deletions
@@ -280,11 +280,6 @@ class TestTftpyState(unittest.TestCase): self.clientServerDownloadOptions({}) tftpy.TftpStates.DELAY_BLOCK = 0 - def testClientServerNoOptionsUnreliable(self): - tftpy.TftpStates.NETWORK_UNRELIABILITY = 1000 - self.clientServerDownloadOptions({}) - tftpy.TftpStates.NETWORK_UNRELIABILITY = 0 - def testServerNoOptions(self): raddress = "127.0.0.2" rport = 10000 @@ -321,6 +316,45 @@ class TestTftpyState(unittest.TestCase): finalstate = serverstate.state.handle(ack, raddress, rport) self.assertTrue(finalstate is None) + def testServerNoOptionsUnreliable(self): + log.debug("===> Running testcase testClientServerNoOptionsUnreliable") + tftpy.TftpStates.NETWORK_UNRELIABILITY = 1000 + raddress = "127.0.0.2" + rport = 10000 + timeout = 5 + root = os.path.dirname(os.path.abspath(__file__)) + # Testing without the dyn_func_file set. + serverstate = tftpy.TftpContexts.TftpContextServer( + raddress, rport, timeout, root + ) + + self.assertTrue(isinstance(serverstate, tftpy.TftpContexts.TftpContextServer)) + + rrq = tftpy.TftpPacketTypes.TftpPacketRRQ() + rrq.filename = "640KBFILE" + rrq.mode = "octet" + rrq.options = {} + + # Start the download. + serverstate.start(rrq.encode().buffer) + # At a 512 byte blocksize, this should be 1280 packets exactly. + for block in range(1, 1281): + # Should be in expectack state. + self.assertTrue( + isinstance(serverstate.state, tftpy.TftpStates.TftpStateExpectACK) + ) + ack = tftpy.TftpPacketTypes.TftpPacketACK() + ack.blocknumber = block % 65536 + serverstate.state = serverstate.state.handle(ack, raddress, rport) + + # The last DAT packet should be empty, indicating a completed + # transfer. + ack = tftpy.TftpPacketTypes.TftpPacketACK() + ack.blocknumber = 1281 % 65536 + finalstate = serverstate.state.handle(ack, raddress, rport) + self.assertTrue(finalstate is None) + tftpy.TftpStates.NETWORK_UNRELIABILITY = 0 + def testServerNoOptionsSubdir(self): raddress = "127.0.0.2" rport = 10000 diff --git a/tftpy/TftpContexts.py b/tftpy/TftpContexts.py index 0a82c8d..d4f127c 100644 --- a/tftpy/TftpContexts.py +++ b/tftpy/TftpContexts.py @@ -268,6 +268,7 @@ class TftpContextServer(TftpContext): TftpContext.end(self) self.metrics.end_time = time.time() log.debug("Set metrics.end_time to %s", self.metrics.end_time) + log.debug("Detected dups in transfer: %d", self.metrics.dupcount) self.metrics.compute() |