Beispiel #1
0
 def testBlock(self):
     d = Deque()
     Tasklet.later(1.0, d.append)(20)
     s = time.time()
     #should block on pop
     self.assertEquals(20, d.pop(True))
     e = time.time()
     self.assertTrue((e - s) > 1.0)
Beispiel #2
0
def main(timeout = None):

    logging.basicConfig()
    logging.root.setLevel(logging.DEBUG)

    if timeout is not None:
        Tasklet.later(timeout, quit, name = 'unittest_timeout')(EXIT_CODE_TIMEOUT)
        
    dispatch(unittest.main)
Beispiel #3
0
def main(timeout=None):

    logging.basicConfig()
    logging.root.setLevel(logging.DEBUG)

    if timeout is not None:
        Tasklet.later(timeout, quit,
                      name='unittest_timeout')(EXIT_CODE_TIMEOUT)

    dispatch(unittest.main)
Beispiel #4
0
 def testBlock2(self):
     d = Deque()
     Tasklet.later(0.5, d.append)(10)
     Tasklet.later(1.0, d.append)(20)
     Tasklet.sleep(1.5)
     s = time.time()
     #should not block
     self.assertEquals(20, d.pop(True))
     self.assertEquals(10, d.pop(True))
     e = time.time()
     self.assertAlmostEqual(0.0, (e - s), places = 1)
Beispiel #5
0
    def testSendTimeout(self):
        #send within timeout

        test_channel = Channel()
        tl = Tasklet.later(1.0, test_channel.receive)()
        try:            
            test_channel.send(10, 2.0)
        except TimeoutError:
            self.fail('did not expect timeout')
        finally:
            tl.kill()
        
        #send with timeout
        test_channel = Channel()
        tl = Tasklet.later(2.0, test_channel.receive)()
        try:            
            test_channel.send(10, 1.0)
            self.fail('expected timeout')
        except TimeoutError:
            pass #expected
        finally:
            tl.kill()
Beispiel #6
0
 def testRecvTimeout(self):
     
     #receive within timeout
     test_channel = Channel()
     t1 = Tasklet.later(1.0, test_channel.send)(10)
     try:            
         self.assertEqual(10, test_channel.receive(2.0))
     except TimeoutError:
         self.fail('did not expect timeout')
     finally:
         t1.kill()
     
     #receive with timeout
     test_channel = Channel()
     t1 = Tasklet.later(2.0, test_channel.send)(10)
     try:            
         self.assertEqual(10, test_channel.receive(1.0))
         self.fail('expected timeout')
     except TimeoutError:
         pass #expected
     finally:
         t1.kill()
Beispiel #7
0
    def testSendTimeout(self):
        #send within timeout

        test_channel = Channel()
        tl = Tasklet.later(1.0, test_channel.receive)()
        try:
            test_channel.send(10, 2.0)
        except TimeoutError:
            self.fail('did not expect timeout')
        finally:
            tl.kill()

        #send with timeout
        test_channel = Channel()
        tl = Tasklet.later(2.0, test_channel.receive)()
        try:
            test_channel.send(10, 1.0)
            self.fail('expected timeout')
        except TimeoutError:
            pass  #expected
        finally:
            tl.kill()
Beispiel #8
0
    def testRecvTimeout(self):

        #receive within timeout
        test_channel = Channel()
        t1 = Tasklet.later(1.0, test_channel.send)(10)
        try:
            self.assertEqual(10, test_channel.receive(2.0))
        except TimeoutError:
            self.fail('did not expect timeout')
        finally:
            t1.kill()

        #receive with timeout
        test_channel = Channel()
        t1 = Tasklet.later(2.0, test_channel.send)(10)
        try:
            self.assertEqual(10, test_channel.receive(1.0))
            self.fail('expected timeout')
        except TimeoutError:
            pass  #expected
        finally:
            t1.kill()
Beispiel #9
0
def main(timeout = None):

    logging.basicConfig()
    logging.root.setLevel(logging.DEBUG)

    if timeout is not None:
        def quit_test():
            logging.error("quiting unittest on timeout")
            quit(EXIT_CODE_TIMEOUT)
        logging.debug("test will timeout in %s seconds", timeout)
        timeout_task = Tasklet.later(timeout, quit_test, name = 'unittest_timeout')()

    from concurrence.core import _profile
    #_profile(unittest.main)
    dispatch(unittest.main)
Beispiel #10
0
    def testJoinKill(self):
        """tests that we can join a tasklet that gets killed"""
        def child(i):   
            Tasklet.sleep(1000)
        
        def killer(t):
            t.kill()

        ch1 = Tasklet.new(child)(1)
        ch2 = Tasklet.later(1, killer)(ch1)  

        try:
            Tasklet.join(ch1)
            self.fail('expected join error')
        except JoinError, e:
            self.assertEquals(ch1, e.tasklet) 
            self.assertTrue(isinstance(e.cause, TaskletExit))
Beispiel #11
0
    def testJoinKill(self):
        """tests that we can join a tasklet that gets killed"""
        def child(i):
            Tasklet.sleep(1000)

        def killer(t):
            t.kill()

        ch1 = Tasklet.new(child)(1)
        ch2 = Tasklet.later(1, killer)(ch1)

        try:
            Tasklet.join(ch1)
            self.fail('expected join error')
        except JoinError, e:
            self.assertEquals(ch1, e.tasklet)
            self.assertTrue(isinstance(e.cause, TaskletExit))
Beispiel #12
0
def main(timeout = None, ontimeout = None):

    logging.basicConfig()
    logging.root.setLevel(logging.DEBUG)

    if timeout is not None:
        def quit_test():
            if ontimeout:
                ontimeout()
            logging.error("quiting unittest on timeout")
            quit(EXIT_CODE_TIMEOUT)
        logging.debug("test will timeout in %s seconds", timeout)
        timeout_task = Tasklet.later(timeout, quit_test, name = 'unittest_timeout')()

    from concurrence.core import _profile
    #_profile(unittest.main)
    dispatch(unittest.main)