Ejemplo n.º 1
0
        async def inner():
            print('Starting server')
            server_future = asyncio.ensure_future(self.server.serve_forever())

            print('Creating client service')
            client = ClientSessionService(f'tcp:127.0.0.1:{self.port}', 'test', 'secret')
            client.subscribe('test-chan')
            client.startService()

            # Wait till client connected
            await client.whenConnected.asFuture(self.loop)

            assert prometheus.REGISTRY.get_sample_value('hpfeeds_broker_client_connections') == 1
            assert prometheus.REGISTRY.get_sample_value('hpfeeds_broker_connection_made') == 1

            print('Publishing test message')
            client.publish('test-chan', b'test message')

            print('Waiting for read()')
            assert ('test', 'test-chan', b'test message') == await client.read().asFuture(self.loop)

            # We would test this after call to subscribe, but need to wait until sure server has processed command
            assert prometheus.REGISTRY.get_sample_value('hpfeeds_broker_subscriptions', {'ident': 'test', 'chan': 'test-chan'}) == 1

            # This will only have incremented when server has processed auth message
            # Test can only reliably assert this is the case after reading a message
            assert prometheus.REGISTRY.get_sample_value('hpfeeds_broker_connection_ready', {'ident': 'test'}) == 1

            print('Stopping client')
            await client.stopService().asFuture(self.loop)

            print('Stopping server')
            server_future.cancel()
            await server_future
Ejemplo n.º 2
0
        def inner(reactor):
            print('Creating client service')

            from twisted.internet import reactor
            endpoint = HostnameEndpoint(reactor, '127.0.0.1', self.server.port)

            client = ClientSessionService(endpoint, 'test', 'secret')
            client.subscribe('test-chan')

            print('Starting client service')
            client.startService()

            # Wait till client connected
            print('Waiting to be connected')
            yield client.whenConnected

            print('Publishing test message')
            client.publish('test-chan', b'test message')

            print('Waiting for read()')
            payload = yield client.read()
            assert ('test', 'test-chan', b'test message') == payload

            print('Stopping client')
            yield client.stopService()

            print('Stopping server for reals')
            yield self.server.close()
Ejemplo n.º 3
0
        def inner(reactor):
            print('Creating client service')
            endpoint = 'tcp:127.0.0.1:{}'.format(self.server.port)
            client = ClientSessionService(endpoint, 'test', 'secret')
            client.subscribe('test-chan')

            print('Starting client service')
            client.startService()

            # Wait till client connected
            print('Waiting to be connected')
            yield client.whenConnected

            print('Publishing test message')
            client.publish('test-chan', b'test message')

            print('Waiting for read()')
            payload = yield client.read()
            assert ('test', 'test-chan', b'test message') == payload

            print('Stopping client')
            yield client.stopService()

            print('Stopping server for reals')
            yield self.server.close()
Ejemplo n.º 4
0
        async def inner(reactor):
            print('Creating client service')
            client = ClientSessionService(f'tcp:127.0.0.1:{self.server.port}', 'test', 'secret')
            client.subscribe('test-chan')

            print('Starting client service')
            client.startService()

            # Wait till client connected
            print('Waiting to be connected')
            await client.whenConnected

            print('Publishing test message')
            client.publish('test-chan', b'test message')

            print('Waiting for read()')
            assert ('test', 'test-chan', b'test message') == client.read()

            print('Stopping client')
            await client.stopService()

            print('Stopping server for reals')
            await self.server.close()