def test_setRunTimeout (self): c = NDN () c.run(0) def change_timeout(): # print("Changing timeout!") c.setRunTimeout(1000) t = Timer(0.1, change_timeout) t.start() org_start = datetime.now() while True: self.assertLess ((datetime.now() - org_start).seconds, 3) # setRunTimeout() failed start = datetime.now() c.run(5) diff = datetime.now() - start if diff.seconds * 1000000 + diff.microseconds > 500000: break
def test_setRunTimeout(self): c = NDN() c.run(0) def change_timeout(): # print("Changing timeout!") c.setRunTimeout(1000) t = Timer(0.1, change_timeout) t.start() org_start = datetime.now() while True: self.assertLess((datetime.now() - org_start).seconds, 3) # setRunTimeout() failed start = datetime.now() c.run(5) diff = datetime.now() - start if diff.seconds * 1000000 + diff.microseconds > 500000: break
from threading import Timer from datetime import datetime handle = _pyndn.create() try: _pyndn.run(handle, 100) except _pyndn.NDNError: pass else: raise AssertionError("ndn_run() should fail when not connected") del handle c = NDN() c.run(0) def change_timeout(): print("Changing timeout!") c.setRunTimeout(1000) t = Timer(0.1, change_timeout) t.start() org_start = datetime.now() while True: if (datetime.now() - org_start).seconds > 3: raise AssertionError("setRunTimeout() failed")
from pyndn import NDN, Name, Interest, Closure from time import sleep worked = False class MyClosure(Closure): def upcall(self, kind, upcallInfo): global worked print("Got response") print(kind) print(upcallInfo) worked = True n = Name("ndn:/ndnx/ping") i = Interest() closure = MyClosure() c = NDN() res = c.expressInterest(n, closure, i) print(res) #causes crashes c.run(10) print("Ha!") assert(worked)