예제 #1
0
    def test_unrelated_rpcs_are_unaffected(self):
        global PORT
        hub = junction.Hub(("127.0.0.1", PORT), [])
        PORT += 2

        @hub.accept_rpc('service', 0, 0, 'method')
        def handle():
            backend.pause_for(TIMEOUT)
            return 1

        hub.start()

        peer = junction.Hub(("127.0.0.1", PORT), [hub.addr])
        PORT += 2
        peer.start()
        peer.wait_connected()

        client = junction.Client(hub.addr)
        client.connect()
        client.wait_connected()
        client = [client]

        backend.schedule(self.kill_client, (client, ))

        # hub does a self-rpc during which the client connection goes away
        result = peer.rpc('service', 0, 'method')

        self.assertEqual(result, 1)
예제 #2
0
    def test_unrelated_rpcs_are_unaffected(self):
        global PORT
        hub = junction.Hub(("127.0.0.1", PORT), [])
        PORT += 2

        @hub.accept_rpc('service', 0, 0, 'method')
        def handle():
            backend.pause_for(TIMEOUT)
            return 1

        hub.start()

        peer = junction.Hub(("127.0.0.1", PORT), [hub.addr])
        PORT += 2
        peer.start()
        peer.wait_connected()

        client = junction.Client(hub.addr)
        client.connect()
        client.wait_connected()
        client = [client]

        backend.schedule(self.kill_client, (client,))

        # hub does a self-rpc during which the client connection goes away
        result = peer.rpc('service', 0, 'method')

        self.assertEqual(result, 1)
예제 #3
0
    def test_unrelated_client_chunked_publishes_are_unrelated(self):
        global PORT
        hub = junction.Hub(("127.0.0.1", PORT), [])
        PORT += 2

        d = {}

        @hub.accept_publish('service', 0, 0, 'method')
        def handle(x, source):
            for item in x:
                d.setdefault(source, 0)
                d[source] += 1

        hub.start()

        c1 = junction.Client(("127.0.0.1", PORT - 2))
        c1.connect()
        c1.wait_connected()
        c2 = junction.Client(("127.0.0.1", PORT - 2))
        c2.connect()
        c2.wait_connected()

        def gen():
            backend.pause_for(TIMEOUT)
            yield None
            backend.pause_for(TIMEOUT)
            yield None
            backend.pause_for(TIMEOUT)
            yield None

        backend.schedule(c1.publish,
                         args=('service', 0, 'method'),
                         kwargs={
                             'args': (gen(), ),
                             'kwargs': {
                                 'source': 'a'
                             }
                         })
        backend.schedule(c2.publish,
                         args=('service', 0, 'method'),
                         kwargs={
                             'args': (gen(), ),
                             'kwargs': {
                                 'source': 'b'
                             }
                         })

        backend.pause_for(TIMEOUT)

        c2 = [c2]
        self.kill_client(c2)

        backend.pause_for(TIMEOUT)
        backend.pause_for(TIMEOUT)
        backend.pause_for(TIMEOUT)

        self.assertEquals(d, {'a': 3, 'b': 1})
예제 #4
0
    def test_unrelated_client_chunked_publishes_are_unrelated(self):
        global PORT
        hub = junction.Hub(("127.0.0.1", PORT), [])
        PORT += 2

        d = {}

        @hub.accept_publish('service', 0, 0, 'method')
        def handle(x, source):
            for item in x:
                d.setdefault(source, 0)
                d[source] += 1

        hub.start()

        c1 = junction.Client(("127.0.0.1", PORT - 2))
        c1.connect()
        c1.wait_connected()
        c2 = junction.Client(("127.0.0.1", PORT - 2))
        c2.connect()
        c2.wait_connected()

        def gen():
            backend.pause_for(TIMEOUT)
            yield None
            backend.pause_for(TIMEOUT)
            yield None
            backend.pause_for(TIMEOUT)
            yield None

        backend.schedule(c1.publish, args=('service', 0, 'method'),
                kwargs={'args': (gen(),), 'kwargs': {'source': 'a'}})
        backend.schedule(c2.publish, args=('service', 0, 'method'),
                kwargs={'args': (gen(),), 'kwargs': {'source': 'b'}})

        backend.pause_for(TIMEOUT)

        c2 = [c2]
        self.kill_client(c2)

        backend.pause_for(TIMEOUT)
        backend.pause_for(TIMEOUT)
        backend.pause_for(TIMEOUT)

        self.assertEquals(d, {'a': 3, 'b': 1})