Skip to content

Commit

Permalink
add another sending timeout unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
SkypLabs committed Jan 6, 2016
1 parent 336cf67 commit d4cd12c
Showing 1 changed file with 41 additions and 1 deletion.
42 changes: 41 additions & 1 deletion test/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def write_func(data):

write_func.data = None

hdlc_c = HDLController(read_func, write_func, sending_timeout=2)
hdlc_c = HDLController(read_func, write_func)
hdlc_c.send('test')
while write_func.data == None: pass
self.assertEqual(write_func.data, frame_data('test', FRAME_DATA, 0))
Expand All @@ -105,6 +105,46 @@ def write_func(data):
self.assertEqual(hdlc_c.get_senders_number(), 1)
hdlc_c.stop()

def test_send_three_frames_and_wait_timeout(self):
def read_func():
pass

def write_func(data):
write_func.data = data

write_func.data = None

hdlc_c = HDLController(read_func, write_func, sending_timeout=5)
hdlc_c.send('test1')
while write_func.data == None: pass
self.assertEqual(write_func.data, frame_data('test1', FRAME_DATA, 0))
self.assertEqual(hdlc_c.get_senders_number(), 1)
write_func.data = None
sleep(1)
hdlc_c.send('test2')
while write_func.data == None: pass
self.assertEqual(write_func.data, frame_data('test2', FRAME_DATA, 1))
self.assertEqual(hdlc_c.get_senders_number(), 2)
write_func.data = None
sleep(1)
hdlc_c.send('test3')
while write_func.data == None: pass
self.assertEqual(write_func.data, frame_data('test3', FRAME_DATA, 2))
self.assertEqual(hdlc_c.get_senders_number(), 3)
write_func.data = None
while write_func.data == None: pass
self.assertEqual(write_func.data, frame_data('test1', FRAME_DATA, 0))
self.assertEqual(hdlc_c.get_senders_number(), 3)
write_func.data = None
while write_func.data == None: pass
self.assertEqual(write_func.data, frame_data('test2', FRAME_DATA, 1))
self.assertEqual(hdlc_c.get_senders_number(), 3)
write_func.data = None
while write_func.data == None: pass
self.assertEqual(write_func.data, frame_data('test3', FRAME_DATA, 2))
self.assertEqual(hdlc_c.get_senders_number(), 3)
hdlc_c.stop()

def test_send_frame_and_receive_ack(self):
def read_func():
return frame_data('', FRAME_ACK, 1)
Expand Down

0 comments on commit d4cd12c

Please sign in to comment.