def test_send_request(self):
        """Very high level test.

        Calling methods to insure they do not raise exception.

        """
        client = InspectingClientAsync(self.host, self.port,
                                       ioloop=self.io_loop,
                                       initial_inspection=False)

        yield client.connect()
        yield client.until_connected()
        yield client.until_synced()
        self.assertEquals(len(client.sensors), 0)

        self.assertEquals(len(client.requests), 0)
        self.assertTrue(client.synced)
        self.assertTrue(client.is_connected())
        self.assertTrue(client.connected)
        yield client.simple_request('sensor-sampling', 'an.int', 'event')
        # Wait for sync and check if the sensor was automaticaly added.
        # Get the sensor object and see if it has data.
        sensor = yield client.future_get_sensor('an.int')
        self.assertEquals(len(client.sensors), 1)
        self.assertTrue(sensor.read())
        self.assertEquals(len(client.requests), 0)
    def setUp(self):
        super(TestICAClass, self).setUp()
        self.client = InspectingClientAsync('',
                                            0,
                                            initial_inspection=False,
                                            ioloop=self.io_loop)

        self.client.set_state_callback(self._cb_state)
    def setUp(self):
        super(TestInspectingClientAsync, self).setUp()
        self.server = DeviceTestServer('', 0)
        start_thread_with_cleanup(self, self.server, start_timeout=1)
        self.host, self.port = self.server.bind_address

        self.client = InspectingClientAsync(self.host, self.port,
                                            ioloop=self.io_loop)
        self.io_loop.add_callback(self.client.connect)
 def setUp(self):
     super(TestInspectingClientAsyncStateCallback, self).setUp()
     self.server = DeviceTestServer('', 0)
     start_thread_with_cleanup(self, self.server, start_timeout=1)
     self.host, self.port = self.server.bind_address
     self.state_cb_future = tornado.concurrent.Future()
     self.client = InspectingClientAsync(self.host, self.port,
                                         ioloop=self.io_loop)
     # Set a short initial_resync timeout to make resync tests quick
     self.client.initial_resync_timeout = 0.001
     self.client.set_state_callback(self._test_state_cb)
     self.done_state_cb_futures = []
     self.cnt_state_cb_futures = collections.defaultdict(tornado.concurrent.Future)
Ejemplo n.º 5
0
    def test_no_memory_leak_after_usage(self):
        client = InspectingClientAsync(self.host, self.port, ioloop=self.io_loop)
        wr = weakref.ref(client)

        yield client.connect()
        yield client.until_synced()
        client.stop()
        yield client.until_stopped()
        client.join()

        # clear strong reference and check if object can be garbage collected
        client = None
        gc.collect()
        self.assertIsNone(wr())
    def _test_inspect_requests(self, timeout_hints):
        """Test  index creation

        Parameters
        ----------
        timeout_hints : bool
            Whether or not the server being tested against should privide
            request timeout hints

        Disables :meth:`InspectingClient.inspect_requests` so that inspecting
        does not happen until the test triggers is. Then checks that
        :attr:`InspectingClient._requests_index` is correctly generated

        """
        host, port, server = self._get_server(hints=timeout_hints)
        DUT = InspectingClientAsync(host, port, ioloop=self.io_loop)
        # mock out the state loop so that syncing does not happen automatically
        DUT._state_loop = mock.Mock()
        # Connect to test server
        yield DUT.connect(timeout=1)
        # Now run the method under test
        yield DUT.inspect_requests()
        expected_request_index = self._get_expected_request_index(server)
        self.assertEqual(DUT._requests_index, expected_request_index)
Ejemplo n.º 7
0
            min(self.durations),
            sum(self.durations) / float(len(self.durations)),
            max(self.durations)))
        print("request had {0} informs with each {1} bytes additional pyload".
              format(self.informs, self.size))
        print("recieved {0} informs in total".format(self.recieved_informs))

    def close(self):
        self.running = False


if __name__ == "__main__":
    args = parse_args()
    print(args.host)
    print(args.port)
    print(args.request_count)

    io_loop = tornado.ioloop.IOLoop.instance()
    ic = InspectingClientAsync(args.host, args.port)
    do_ping = DoPing(ic, args.host, args.request_count, args.inform_count,
                     args.size)
    ic.set_ioloop(io_loop)
    io_loop.add_callback(ic.connect)
    io_loop.add_callback(do_ping.run)
    try:
        io_loop.start()
    except KeyboardInterrupt:
        do_ping.close()
        ic.close()
    do_ping.summary()