Exemplo n.º 1
0
 def test_ref(self):
     err = Error()
     err_ref = weakref.ref(err)
     with Timeout(DELAY * 2, err):
         sleep(DELAY)
     del err
     assert not err_ref(), repr(err_ref())
Exemplo n.º 2
0
    def test_send_during_recv_multipart(self):
        sender, receiver, port = self.create_bound_pair(zmq.XREQ, zmq.XREQ)
        sleep()

        num_recvs = 30
        done_evts = [event.Event() for _ in range(num_recvs)]

        def slow_rx(done, msg):
            self.assertEqual(sender.recv_multipart(), msg)
            done.send(0)

        def tx():
            tx_i = 0
            while tx_i <= 1000:
                sender.send_multipart([str(tx_i), '1', '2', '3'])
                tx_i += 1

        def rx():
            while True:
                rx_i = receiver.recv_multipart()
                if rx_i == ["1000", '1', '2', '3']:
                    for i in range(num_recvs):
                        receiver.send_multipart(['done%d' % i, 'a', 'b', 'c'])
                    sleep()
                    return

        for i in range(num_recvs):
            spawn(slow_rx, done_evts[i], ["done%d" % i, 'a', 'b', 'c'])

        spawn(tx)
        spawn(rx)
        for i in range(num_recvs):
            final_i = done_evts[i].wait()
            self.assertEqual(final_i, 0)
Exemplo n.º 3
0
 def test_cancel_timer_inside_block(self):
     """
     Testing that it's possible to cancel the timer inside the block
     """
     with Timeout(DELAY) as timer:
         timer.cancel()
         sleep(DELAY * 2)
Exemplo n.º 4
0
    def test_pipe_read(self):
        # ensure that 'readline' works properly on GreenPipes when data is not
        # immediately available (fd is nonblocking, was raising EAGAIN)
        # also ensures that readline() terminates on '\n' and '\r\n'
        r, w = os.pipe()

        r = GreenPipe(r)
        w = GreenPipe(w, 'w')

        def writer():
            sleep(.1)

            w.write('line\n')
            w.flush()

            w.write('line\r\n')
            w.flush()

        gt = spawn(writer)

        sleep(0)

        line = r.readline()
        self.assertEquals(line, 'line\n')

        line = r.readline()
        self.assertEquals(line, 'line\r\n')

        gt.wait()
Exemplo n.º 5
0
 def tick():
     for i in xrange(20000):
         counter[0] += 1
         if counter[0] % 20 == 0:
             sleep(0.0001)
         else:
             sleep()
Exemplo n.º 6
0
 def client ():
     client = sockets.GreenSocket()
     accepting.wait()
     sleep(0.5)
     client.connect(('127.0.0.1', port))
     received_data = client.recv(5000)
     received.send(received_data)
Exemplo n.º 7
0
    def test_send_during_recv(self):
        sender, receiver, port = self.create_bound_pair(zmq.XREQ, zmq.XREQ)
        sleep()

        num_recvs = 30
        done_evts = [event.Event() for _ in range(num_recvs)]

        def slow_rx(done, msg):
            self.assertEqual(sender.recv(), msg)
            done.send(0)

        def tx():
            tx_i = 0
            while tx_i <= 1000:
                sender.send(str(tx_i))
                tx_i += 1

        def rx():
            while True:
                rx_i = receiver.recv()
                if rx_i == "1000":
                    for i in range(num_recvs):
                        receiver.send('done%d' % i)
                    sleep()
                    return

        for i in range(num_recvs):
            spawn(slow_rx, done_evts[i], "done%d" % i)

        spawn(tx)
        spawn(rx)
        for evt in done_evts:
            self.assertEqual(evt.wait(), 0)
Exemplo n.º 8
0
    def test_channel_wait(self):
        channel = Queue(0)
        events = []

        def another_greenlet():
            events.append('sending hello')
            channel.put('hello')
            events.append('sending world')
            channel.put('world')
            events.append('sent world')

        gt = spawn(another_greenlet)

        events.append('waiting')
        events.append(channel.get())
        events.append(channel.get())

        self.assertEqual(
            ['waiting', 'sending hello', 'hello', 'sending world', 'world'],
            events)
        sleep(0)
        self.assertEqual([
            'waiting', 'sending hello', 'hello', 'sending world', 'world',
            'sent world'
        ], events)
Exemplo n.º 9
0
 def test_dummy_timer(self):
     """
     Testing that passing None as seconds disables the timer
     """
     with Timeout(None):
         sleep(DELAY)
     sleep(DELAY)
Exemplo n.º 10
0
    def test_killing_dormant (self):
        DELAY = 0.1
        state = []

        def test ():
            try:
                state.append('start')
                sleep(DELAY)
            except:
                state.append('except')
                # catching GreenletExit
                pass
                # when switching to hub, hub makes itself the parent of this greenlet,
            # thus after the function's done, the control will go to the parent
            sleep(0)
            state.append('finished')

        g = spawn(test)
        sleep(DELAY / 2)
        self.assertEquals(state, ['start'])
        kill(g)
        # will not get there, unless switching is explicitly scheduled by kill
        self.assertEquals(state, ['start', 'except'])
        sleep(DELAY)
        self.assertEquals(state, ['start', 'except', 'finished'])
Exemplo n.º 11
0
 def tx(sock):
     for i in range(1, 1001):
         msg = "sub%s %s" % ([2, 1][i % 2], i)
         sock.send(msg)
         sleep()
     sock.send('sub1 LAST')
     sock.send('sub2 LAST')
Exemplo n.º 12
0
    def test_send_1k_req_rep (self):
        req, rep, port = self.create_bound_pair(zmq.REQ, zmq.REP)
        sleep()
        done = event.Event()

        def tx ():
            tx_i = 0
            req.send(str(tx_i))
            while req.recv() != 'done':
                tx_i += 1
                req.send(str(tx_i))
            done.send(0)

        def rx ():
            while True:
                rx_i = rep.recv()
                if rx_i == "1000":
                    rep.send('done')
                    break
                rep.send('i')

        spawn(tx)
        spawn(rx)
        final_i = done.wait()
        self.assertEqual(final_i, 0)
Exemplo n.º 13
0
    def test_nested_acquire(self):
        q = zmq._QueueLock()
        self.assertFalse(q)
        q.acquire()
        q.acquire()

        s = semaphore.Semaphore(0)
        results = []

        def lock(x):
            with q:
                results.append(x)
            s.release()

        spawn(lock, 1)
        sleep()
        self.assertEquals(results, [])
        q.release()
        sleep()
        self.assertEquals(results, [])
        self.assertTrue(q)
        q.release()

        s.acquire()
        self.assertEquals(results, [1])
Exemplo n.º 14
0
    def test_resize(self):
        pool = GreenPool(2)
        evt = Event()

        def wait_long_time(e):
            e.wait()

        pool.spawn(wait_long_time, evt)
        pool.spawn(wait_long_time, evt)
        self.assertEquals(pool.free(), 0)
        self.assert_pool_has_free(pool, 0)

        # verify that the pool discards excess items put into it
        pool.resize(1)

        # cause the wait_long_time functions to return, which will
        # trigger puts to the pool
        evt.send(None)
        sleep(0)
        sleep(0)

        self.assertEquals(pool.free(), 1)
        self.assert_pool_has_free(pool, 1)

        # resize larger and assert that there are more free items
        pool.resize(2)
        self.assertEquals(pool.free(), 2)
        self.assert_pool_has_free(pool, 2)
Exemplo n.º 15
0
    def imap_memory_check(self, concurrency):
        # checks that imap is strictly
        # ordered and consumes a constant amount of memory
        p = GreenPool(concurrency)
        count = 1000
        it = p.imap(passthru, xrange(count))
        latest = -1
        while True:
            try:
                i = it.next()
            except StopIteration:
                break

            if latest == -1:
                gc.collect()
                initial_obj_count = len(gc.get_objects())
            self.assert_(i > latest)
            latest = i
            if latest % 5 == 0:
                sleep(0.001)
            if latest % 10 == 0:
                gc.collect()
                objs_created = len(gc.get_objects()) - initial_obj_count
                self.assert_(objs_created < 25 * concurrency, objs_created)
                # make sure we got to the end
        self.assertEquals(latest, count - 1)
Exemplo n.º 16
0
def pressure(arg):
    while r.random() < 0.5:
        sleep(r.random() * 0.001)
    if r.random() < 0.8:
        return arg
    else:
        raise StressException(arg)
Exemplo n.º 17
0
def pressure (arg):
    while r.random() < 0.5:
        sleep(r.random() * 0.001)
    if r.random() < 0.8:
        return arg
    else:
        raise StressException(arg)
Exemplo n.º 18
0
    def test_send_1k_req_rep(self):
        req, rep, port = self.create_bound_pair(zmq.REQ, zmq.REP)
        sleep()
        done = event.Event()

        def tx():
            tx_i = 0
            req.send(str(tx_i))
            while req.recv() != 'done':
                tx_i += 1
                req.send(str(tx_i))
            done.send(0)

        def rx():
            while True:
                rx_i = rep.recv()
                if rx_i == "1000":
                    rep.send('done')
                    break
                rep.send('i')

        spawn(tx)
        spawn(rx)
        final_i = done.wait()
        self.assertEqual(final_i, 0)
Exemplo n.º 19
0
    def assert_pool_has_free(self, pool, num_free):
        self.assertEquals(pool.free(), num_free)

        def wait_long_time(e):
            e.wait()

        timer = Timeout(1)
        try:
            evt = Event()
            for x in xrange(num_free):
                pool.spawn(wait_long_time, evt)
                # if the pool has fewer free than we expect,
                # then we'll hit the timeout error
        finally:
            timer.cancel()

        # if the runtime error is not raised it means the pool had
        # some unexpected free items
        timer = Timeout(0, RuntimeError)
        try:
            self.assertRaises(RuntimeError, pool.spawn, wait_long_time, evt)
        finally:
            timer.cancel()

        # clean up by causing all the wait_long_time functions to return
        evt.send(None)
        sleep(0)
        sleep(0)
Exemplo n.º 20
0
    def test_send_during_recv (self):
        sender, receiver, port = self.create_bound_pair(zmq.XREQ, zmq.XREQ)
        sleep()

        num_recvs = 30
        done_evts = [event.Event() for _ in range(num_recvs)]

        def slow_rx (done, msg):
            self.assertEqual(sender.recv(), msg)
            done.send(0)

        def tx ():
            tx_i = 0
            while tx_i <= 1000:
                sender.send(str(tx_i))
                tx_i += 1

        def rx ():
            while True:
                rx_i = receiver.recv()
                if rx_i == "1000":
                    for i in range(num_recvs):
                        receiver.send('done%d' % i)
                    sleep()
                    return

        for i in range(num_recvs):
            spawn(slow_rx, done_evts[i], "done%d" % i)

        spawn(tx)
        spawn(rx)
        for evt in done_evts:
            self.assertEqual(evt.wait(), 0)
Exemplo n.º 21
0
    def test_sending_messages_to_websocket_76 (self):
        connect_data = [
            "GET /echo HTTP/1.1",
            "Upgrade: WebSocket",
            "Connection: Upgrade",
            "Host: localhost:%s" % self.port,
            "Origin: http://localhost:%s" % self.port,
            "Sec-WebSocket-Protocol: ws",
            "Sec-WebSocket-Key1: 4 @1  46546xW%0l 1 5",
            "Sec-WebSocket-Key2: 12998 5 Y3 1  .P00",
        ]
        sock = connect(
            ('localhost', self.port))

        sock.sendall('\r\n'.join(connect_data) + '\r\n\r\n^n:ds[4U')
        first_resp = sock.recv(1024)
        sock.sendall('\x00hello\xFF')
        result = sock.recv(1024)
        self.assertEqual(result, '\x00hello\xff')
        sock.sendall('\x00start')
        sleep(0.001)
        sock.sendall(' end\xff')
        result = sock.recv(1024)
        self.assertEqual(result, '\x00start end\xff')
        sock.shutdown(socket.SHUT_RDWR)
        sock.close()
        sleep(0.01)
Exemplo n.º 22
0
 def tx (sock):
     for i in range(1, 1001):
         msg = "sub%s %s" % ([2, 1][i % 2], i)
         sock.send(msg)
         sleep()
     sock.send('sub1 LAST')
     sock.send('sub2 LAST')
Exemplo n.º 23
0
    def test_spawn_n_2(self):
        p = GreenPool(2)
        self.assertEqual(p.free(), 2)
        r = []

        def foo(a):
            r.append(a)

        gt = p.spawn(foo, 1)
        self.assertEqual(p.free(), 1)
        gt.wait()
        self.assertEqual(r, [1])
        sleep(0)
        self.assertEqual(p.free(), 2)

        # Once the pool is exhausted, spawning forces a yield.
        p.spawn_n(foo, 2)
        self.assertEqual(1, p.free())
        self.assertEqual(r, [1])

        p.spawn_n(foo, 3)
        self.assertEqual(0, p.free())
        self.assertEqual(r, [1])

        p.spawn_n(foo, 4)
        self.assertEqual(set(r), set([1, 2, 3]))
        sleep(0)
        self.assertEqual(set(r), set([1, 2, 3, 4]))
Exemplo n.º 24
0
    def test_blocks_on_pool(self):
        waiter = Queue(0)

        def greedy():
            self.pool.get()
            self.pool.get()
            self.pool.get()
            self.pool.get()
            # No one should be waiting yet.
            self.assertEquals(self.pool.waiting(), 0)
            # The call to the next get will unschedule this routine.
            self.pool.get()
            # So this put should never be called.
            waiter.put('Failed!')

        killable = spawn(greedy)

        # no one should be waiting yet.
        self.assertEquals(self.pool.waiting(), 0)

        ## Wait for greedy
        sleep(0)

        ## Greedy should be blocking on the last get
        self.assertEquals(self.pool.waiting(), 1)

        ## Send will never be called, so balance should be 0.
        self.assertFalse(not waiter.full())

        kill(killable)
Exemplo n.º 25
0
    def test_blocks_on_pool (self):
        waiter = Queue(0)

        def greedy ():
            self.pool.get()
            self.pool.get()
            self.pool.get()
            self.pool.get()
            # No one should be waiting yet.
            self.assertEquals(self.pool.waiting(), 0)
            # The call to the next get will unschedule this routine.
            self.pool.get()
            # So this put should never be called.
            waiter.put('Failed!')

        killable = spawn(greedy)

        # no one should be waiting yet.
        self.assertEquals(self.pool.waiting(), 0)

        ## Wait for greedy
        sleep(0)

        ## Greedy should be blocking on the last get
        self.assertEquals(self.pool.waiting(), 1)

        ## Send will never be called, so balance should be 0.
        self.assertFalse(not waiter.full())

        kill(killable)
Exemplo n.º 26
0
    def test_resize(self):
        pool = GreenPool(2)
        evt = Event()

        def wait_long_time(e):
            e.wait()

        pool.spawn(wait_long_time, evt)
        pool.spawn(wait_long_time, evt)
        self.assertEquals(pool.free(), 0)
        self.assert_pool_has_free(pool, 0)

        # verify that the pool discards excess items put into it
        pool.resize(1)

        # cause the wait_long_time functions to return, which will
        # trigger puts to the pool
        evt.send(None)
        sleep(0)
        sleep(0)

        self.assertEquals(pool.free(), 1)
        self.assert_pool_has_free(pool, 1)

        # resize larger and assert that there are more free items
        pool.resize(2)
        self.assertEquals(pool.free(), 2)
        self.assert_pool_has_free(pool, 2)
Exemplo n.º 27
0
 def client():
     client = sockets.GreenSocket()
     accepting.wait()
     sleep(0.5)
     client.connect(('127.0.0.1', port))
     received_data = client.recv(5000)
     received.send(received_data)
Exemplo n.º 28
0
    def test_pipe_read (self):
        # ensure that 'readline' works properly on GreenPipes when data is not
        # immediately available (fd is nonblocking, was raising EAGAIN)
        # also ensures that readline() terminates on '\n' and '\r\n'
        r, w = os.pipe()

        r = GreenPipe(r)
        w = GreenPipe(w, 'w')

        def writer ():
            sleep(.1)

            w.write('line\n')
            w.flush()

            w.write('line\r\n')
            w.flush()

        gt = spawn(writer)

        sleep(0)

        line = r.readline()
        self.assertEquals(line, 'line\n')

        line = r.readline()
        self.assertEquals(line, 'line\r\n')

        gt.wait()
Exemplo n.º 29
0
 def tick ():
     for i in xrange(20000):
         counter[0] += 1
         if counter[0] % 20 == 0:
             sleep(0.0001)
         else:
             sleep()
Exemplo n.º 30
0
    def test_killing_dormant(self):
        DELAY = 0.1
        state = []

        def test():
            try:
                state.append('start')
                sleep(DELAY)
            except:
                state.append('except')
                # catching GreenletExit
                pass
                # when switching to hub, hub makes itself the parent of this greenlet,
            # thus after the function's done, the control will go to the parent
            sleep(0)
            state.append('finished')

        g = spawn(test)
        sleep(DELAY / 2)
        self.assertEquals(state, ['start'])
        kill(g)
        # will not get there, unless switching is explicitly scheduled by kill
        self.assertEquals(state, ['start', 'except'])
        sleep(DELAY)
        self.assertEquals(state, ['start', 'except', 'finished'])
Exemplo n.º 31
0
    def test_nested_acquire (self):
        q = zmq._QueueLock()
        self.assertFalse(q)
        q.acquire()
        q.acquire()

        s = semaphore.Semaphore(0)
        results = []

        def lock (x):
            with q:
                results.append(x)
            s.release()

        spawn(lock, 1)
        sleep()
        self.assertEquals(results, [])
        q.release()
        sleep()
        self.assertEquals(results, [])
        self.assertTrue(q)
        q.release()

        s.acquire()
        self.assertEquals(results, [1])
Exemplo n.º 32
0
    def test_send_during_recv_multipart (self):
        sender, receiver, port = self.create_bound_pair(zmq.XREQ, zmq.XREQ)
        sleep()

        num_recvs = 30
        done_evts = [event.Event() for _ in range(num_recvs)]

        def slow_rx (done, msg):
            self.assertEqual(sender.recv_multipart(), msg)
            done.send(0)

        def tx ():
            tx_i = 0
            while tx_i <= 1000:
                sender.send_multipart([str(tx_i), '1', '2', '3'])
                tx_i += 1

        def rx ():
            while True:
                rx_i = receiver.recv_multipart()
                if rx_i == ["1000", '1', '2', '3']:
                    for i in range(num_recvs):
                        receiver.send_multipart(['done%d' % i, 'a', 'b', 'c'])
                    sleep()
                    return

        for i in range(num_recvs):
            spawn(slow_rx, done_evts[i], ["done%d" % i, 'a', 'b', 'c'])

        spawn(tx)
        spawn(rx)
        for i in range(num_recvs):
            final_i = done_evts[i].wait()
            self.assertEqual(final_i, 0)
Exemplo n.º 33
0
    def assert_pool_has_free(self, pool, num_free):
        self.assertEquals(pool.free(), num_free)

        def wait_long_time(e):
            e.wait()

        timer = Timeout(1)
        try:
            evt = Event()
            for x in xrange(num_free):
                pool.spawn(wait_long_time, evt)
                # if the pool has fewer free than we expect,
                # then we'll hit the timeout error
        finally:
            timer.cancel()

        # if the runtime error is not raised it means the pool had
        # some unexpected free items
        timer = Timeout(0, RuntimeError)
        try:
            self.assertRaises(RuntimeError, pool.spawn, wait_long_time, evt)
        finally:
            timer.cancel()

        # clean up by causing all the wait_long_time functions to return
        evt.send(None)
        sleep(0)
        sleep(0)
Exemplo n.º 34
0
    def imap_memory_check (self, concurrency):
        # checks that imap is strictly
        # ordered and consumes a constant amount of memory
        p = GreenPool(concurrency)
        count = 1000
        it = p.imap(passthru, xrange(count))
        latest = -1
        while True:
            try:
                i = it.next()
            except StopIteration:
                break

            if latest == -1:
                gc.collect()
                initial_obj_count = len(gc.get_objects())
            self.assert_(i > latest)
            latest = i
            if latest % 5 == 0:
                sleep(0.001)
            if latest % 10 == 0:
                gc.collect()
                objs_created = len(gc.get_objects()) - initial_obj_count
                self.assert_(objs_created < 25 * concurrency, objs_created)
                # make sure we got to the end
        self.assertEquals(latest, count - 1)
Exemplo n.º 35
0
    def test_spawn_n_2(self):
        p = GreenPool(2)
        self.assertEqual(p.free(), 2)
        r = []

        def foo(a):
            r.append(a)

        gt = p.spawn(foo, 1)
        self.assertEqual(p.free(), 1)
        gt.wait()
        self.assertEqual(r, [1])
        sleep(0)
        self.assertEqual(p.free(), 2)

        #Once the pool is exhausted, spawning forces a yield.
        p.spawn_n(foo, 2)
        self.assertEqual(1, p.free())
        self.assertEqual(r, [1])

        p.spawn_n(foo, 3)
        self.assertEqual(0, p.free())
        self.assertEqual(r, [1])

        p.spawn_n(foo, 4)
        self.assertEqual(set(r), set([1, 2, 3]))
        sleep(0)
        self.assertEqual(set(r), set([1, 2, 3, 4]))
Exemplo n.º 36
0
 def client():
     buf = buffer(array.array('B'))
     client = sockets.GreenSocket()
     accepting.wait()
     sleep(0.5)
     client.connect(('127.0.0.1', port))
     client.recv_into(buf, 5000)
     received.send(buf)
Exemplo n.º 37
0
 def rx ():
     while True:
         rx_i = receiver.recv_multipart()
         if rx_i == ["1000", '1', '2', '3']:
             for i in range(num_recvs):
                 receiver.send_multipart(['done%d' % i, 'a', 'b', 'c'])
             sleep()
             return
Exemplo n.º 38
0
        def sender(evt):
            s2, addr = server.accept()
            wrap_wfile = s2.makefile('w')

            sleep(0.02)
            wrap_wfile.write('hi')
            s2.close()
            evt.send('sent via event')
Exemplo n.º 39
0
def check_hub():
    # Clear through the descriptor queue
    threads.sleep(0)
    threads.sleep(0)
    hub = hubs.get_hub()
    for nm in 'get_readers', 'get_writers':
        dct = getattr(hub, nm)()
        assert not dct, "hub.%s not empty: %s" % (nm, dct)
Exemplo n.º 40
0
 def rx():
     while True:
         rx_i = receiver.recv()
         if rx_i == "1000":
             for i in range(num_recvs):
                 receiver.send('done%d' % i)
             sleep()
             return
Exemplo n.º 41
0
 def rx():
     while True:
         rx_i = receiver.recv_multipart()
         if rx_i == ["1000", '1', '2', '3']:
             for i in range(num_recvs):
                 receiver.send_multipart(['done%d' % i, 'a', 'b', 'c'])
             sleep()
             return
Exemplo n.º 42
0
        def writer ():
            sleep(.1)

            w.write('line\n')
            w.flush()

            w.write('line\r\n')
            w.flush()
Exemplo n.º 43
0
 def test_kill_meth(self):
     gt = spawn(passthru, 6)
     gt.kill()
     self.assert_dead(gt)
     sleep(0.001)
     self.assertEquals(_g_results, [])
     gt.kill()
     self.assert_dead(gt)
Exemplo n.º 44
0
    def test_timer_cancelled_upon_greenlet_exit(self):
        def func():
            spawn_after_local(0.1, self.lst.pop)

        spawn(func)
        assert self.lst == [1], self.lst
        sleep(0.2)
        assert self.lst == [1], self.lst
Exemplo n.º 45
0
 def rx ():
     while True:
         rx_i = receiver.recv()
         if rx_i == "1000":
             for i in range(num_recvs):
                 receiver.send('done%d' % i)
             sleep()
             return
Exemplo n.º 46
0
 def test_kill_n(self):
     gt = spawn_n(passthru, 7)
     kill(gt)
     self.assert_dead(gt)
     sleep(0.001)
     self.assertEquals(_g_results, [])
     kill(gt)
     self.assert_dead(gt)
Exemplo n.º 47
0
    def test_spawn_is_not_cancelled(self):
        def func():
            spawn(self.lst.pop)
            # exiting immediatelly, but self.lst.pop must be called

        spawn(func)
        sleep(0.1)
        assert self.lst == [], self.lst
Exemplo n.º 48
0
    def test_spawn_is_not_cancelled (self):
        def func ():
            spawn(self.lst.pop)
            # exiting immediatelly, but self.lst.pop must be called

        spawn(func)
        sleep(0.1)
        assert self.lst == [], self.lst
Exemplo n.º 49
0
        def sender (evt):
            s2, addr = server.accept()
            wrap_wfile = s2.makefile('w')

            sleep(0.02)
            wrap_wfile.write('hi')
            s2.close()
            evt.send('sent via event')
Exemplo n.º 50
0
 def test_kill_n (self):
     gt = spawn_n(passthru, 7)
     kill(gt)
     self.assert_dead(gt)
     sleep(0.001)
     self.assertEquals(_g_results, [])
     kill(gt)
     self.assert_dead(gt)
Exemplo n.º 51
0
 def test_kill_meth (self):
     gt = spawn(passthru, 6)
     gt.kill()
     self.assert_dead(gt)
     sleep(0.001)
     self.assertEquals(_g_results, [])
     gt.kill()
     self.assert_dead(gt)
Exemplo n.º 52
0
        def writer():
            sleep(.1)

            w.write('line\n')
            w.flush()

            w.write('line\r\n')
            w.flush()
Exemplo n.º 53
0
    def test_timer_cancelled_upon_greenlet_exit (self):
        def func ():
            spawn_after_local(0.1, self.lst.pop)

        spawn(func)
        assert self.lst == [1], self.lst
        sleep(0.2)
        assert self.lst == [1], self.lst
Exemplo n.º 54
0
 def client ():
     buf = buffer(array.array('B'))
     client = sockets.GreenSocket()
     accepting.wait()
     sleep(0.5)
     client.connect(('127.0.0.1', port))
     client.recv_into(buf, 5000)
     received.send(buf)
Exemplo n.º 55
0
 def test_ordering(self):
     lst = []
     hubs.get_hub().schedule_call_global(DELAY * 2, lst.append, 3)
     hubs.get_hub().schedule_call_global(DELAY, lst.append, 1)
     hubs.get_hub().schedule_call_global(DELAY, lst.append, 2)
     while len(lst) < 3:
         sleep(DELAY)
     self.assertEquals(sorted(lst), sorted([1, 2, 3]))
Exemplo n.º 56
0
def check_hub ():
    # Clear through the descriptor queue
    threads.sleep(0)
    threads.sleep(0)
    hub = hubs.get_hub()
    for nm in 'get_readers', 'get_writers':
        dct = getattr(hub, nm)()
        assert not dct, "hub.%s not empty: %s" % (nm, dct)
Exemplo n.º 57
0
 def test_ordering (self):
     lst = []
     hubs.get_hub().schedule_call_global(DELAY * 2, lst.append, 3)
     hubs.get_hub().schedule_call_global(DELAY, lst.append, 1)
     hubs.get_hub().schedule_call_global(DELAY, lst.append, 2)
     while len(lst) < 3:
         sleep(DELAY)
     self.assertEquals(sorted(lst), sorted([1, 2, 3]))
Exemplo n.º 58
0
 def test_two_bogus_waiters(self):
     q = Queue()
     gt1 = spawn(do_bail, q)
     gt2 = spawn(do_bail, q)
     sleep(0)
     q.put('sent')
     self.assertEquals(gt1.wait(), 'timed out')
     self.assertEquals(gt2.wait(), 'timed out')
     self.assertEquals(q.get(), 'sent')
Exemplo n.º 59
0
 def tx(sock):
     for i in range(1, 101):
         msg = "test %s" % i
         if i != 50:
             sock.send(msg)
         else:
             sock.send('test LAST')
         sleep()
     sock.send('done DONE')