Пример #1
0
 def test_with_timeout (self):
     self.assertRaises(timeout.Timeout, timeout.with_timeout, DELAY, greenthread.sleep,
                       DELAY * 10)
     X = object()
     r = timeout.with_timeout(DELAY, greenthread.sleep, DELAY * 10, timeout_value = X)
     self.assert_(r is X, (r, X))
     r = timeout.with_timeout(DELAY * 10, greenthread.sleep,
                              DELAY, timeout_value = X)
     self.assert_(r is None, r)
Пример #2
0
 def test_blocking(self):
     l = convenience.listen(('localhost', 0))
     x = with_timeout(0.01,
                      convenience.serve,
                      l,
                      lambda c, a: None,
                      timeout_value="timeout")
     self.assertEqual(x, "timeout")
Пример #3
0
    def test_concurrency(self):
        evt = event.Event()

        def waiter(sock, addr):
            sock.sendall(s2b('hi'))
            evt.wait()

        l = convenience.listen(('localhost', 0))
        gt = spawn(convenience.serve, l, waiter, 5)

        def test_client():
            c = convenience.connect(('localhost', l.getsockname()[1]))
            # verify the client is connected by getting data
            self.assertEquals(s2b('hi'), c.recv(2))
            return c

        clients = [test_client() for i in xrange(5)]
        # very next client should not get anything
        x = with_timeout(0.01, test_client, timeout_value="timed out")
        self.assertEquals(x, "timed out")
Пример #4
0
    def test_concurrency (self):
        evt = event.Event()

        def waiter (sock, addr):
            sock.sendall(s2b('hi'))
            evt.wait()

        l = convenience.listen(('localhost', 0))
        gt = spawn(convenience.serve, l, waiter, 5)

        def test_client ():
            c = convenience.connect(('localhost', l.getsockname()[1]))
            # verify the client is connected by getting data
            self.assertEquals(s2b('hi'), c.recv(2))
            return c

        clients = [test_client() for i in xrange(5)]
        # very next client should not get anything
        x = with_timeout(0.01, test_client, timeout_value = "timed out")
        self.assertEquals(x, "timed out")
Пример #5
0
 def longer_timeout ():
     # this should not catch the outer timeout's exception
     return timeout.with_timeout(DELAY * 10,
                                 greenthread.sleep, DELAY * 20,
                                 timeout_value = 'b')
Пример #6
0
 def test_blocking (self):
     l = convenience.listen(('localhost', 0))
     x = with_timeout(0.01,
                      convenience.serve, l, lambda c, a: None,
                      timeout_value = "timeout")
     self.assertEqual(x, "timeout")