SeattleTestbed / repy_v1

Seattle Testbed's original Repy version 1 sandbox
MIT License
1 stars 4 forks source link

Unit Test: ut_repytests_testnetmessdup.py won't exit #129

Open choksi81 opened 10 years ago

choksi81 commented 10 years ago

ut_repytests_testnetmessdup.py tries if a registered callbackfunction for incoming UDP messages is properly replaced by a later registered callbackfunction on the same IP and port. Depending on the function that is called upon the reception of a UDP message the test fails or passes. But if none of the functions is called, the test will never exit. I ran into this problem while unit testing on OpenWRT.

A possible patch for this problem would be:

@@ -5,6 +5,7 @@

 def noop(ip,port,mess, ch):
   stopcomm(ch)
+  exitall()

 if callfunc == 'initialize':
   ip = getmyip()
@@ -12,3 +13,5 @@
   recvmess(ip,12345,noop)   # should replace foo
   sleep(.1)
   sendmess(ip,12345,'hi')
+  sleep(10)
+  raise Exception, "Should not get here"
choksi81 commented 10 years ago

Author: albert I suggest to be a little more verbose in our error messages. The exitall() in noop is probably not required by the way. Stopping the listening socket should suffice to end the program.

#pragma repy

def foo(ip,port,mess, ch):
  raise Exception, "Should not get here -- overwriting the UDP callback handler didn't work."

def noop(ip,port,mess, ch):
  stopcomm(ch)
  exitall()

if callfunc == 'initialize':
  ip = getmyip()
  recvmess(ip,<messport>,foo)
  recvmess(ip,<messport>,noop)   # should replace foo
  sleep(.1)
  sendmess(ip,<messport>,'hi')
  sleep(10)
  raise Exception, "Should not get here -- The UDP callback isn't called within my timeout."
choksi81 commented 10 years ago

Author: albert Oh wait, the exitall is required of course! Otherwise, we would sleep(10) in the main thread and raise an exception even if the callback was triggered.

choksi81 commented 10 years ago

Author: lucas Also noticed the problem while testing on Mac and iOS, though the test passed when executed individually. My solution was:

#pragma repy

def foo(ip, port, mess, ch):
  raise Exception, "Should not get here"

def noop(ip, port, mess, ch):
  stopcomm(ch)

def timeout():
  print "Timed out!"
  exitall()

if callfunc == 'initialize':
  # Lucas: set timeout timer
  # This test may hang on some systems, like Mac and iOS 
  timer = settimer(40, timeout, ())

  ip = getmyip()
  recvmess(ip, 12345, foo)
  recvmess(ip, 12345, noop)   # should replace foo
  sleep(.1)
  sendmess(ip, 12345, 'hi')