Exemple #1
0
    def test_factory(self):
        """Test %s RawBroadcaster() from connection."""

        # Manufacture an instance of RawBroadcaster() from the connection
        # object.
        broadcaster = RawBroadcaster(self.connection)
        broadcaster.close()

        # Ensure errors are propagated.
        with self.assertRaises(Exception):
            RawBroadcaster(self.bad_connection)

        # Test instantiation fails if input is not a 'connection' object.
        with self.assertRaises(TypeError):
            RawBroadcaster('connection')
Exemple #2
0
    def test_raw_receive(self):
        """Test %s QueuedListener() raw-data send-receive functionality."""

        listener = QueuedListener(self.Message.connection)
        broadcaster = RawBroadcaster(self.Message.connection)
        data = 'test'
        self.queued_send_receive(listener, broadcaster, data)
Exemple #3
0
    def test_queuedlistener_enqueue(self):
        """Test %s QueuedListener() multiprocess enqueue functionality."""

        # NOTE: QueuedListener is designed to run on a separate
        #       process. The code run on that process is contained within the
        #       class. Exceptions encountered in that will not be caught or
        #       unit tested unless the code is tested directly in this process.
        #       However, the code has been made 'private' as it should not be
        #       called directly and it maintains a clean API. To properly
        #       unit-test this code, the 'private' mangling of the code will be
        #       dodged.

        # Create broadcaster.
        broadcaster = RawBroadcaster(self.Message.connection)

        # Abuse intention of 'private' mangling to get queuing function.
        fcn = QueuedListener._QueuedListener__enqueue
        queue = multiprocessing.Queue()

        # The '__enqueue' method does not reference 'self' so it can be tested
        # on this thread. However, it does block so multi-threading must be
        # used to terminate its operation.
        run_event = threading.Event()
        run_event.set()

        # Launch '__enqueue' method on a new thread.
        thread = threading.Thread(target=fcn,
                                  args=(QueuedListener(self.Message.connection),
                                        run_event,
                                        self.Message.connection,
                                        None,
                                        queue))
        thread.daemon = True
        thread.start()
        time.sleep(DELAY)

        # Publish data via broadcaster.
        test_data = 'test'
        broadcaster.publish(test_data)
        time.sleep(DELAY)

        # Wait for thread to close.
        run_event.clear()
        thread.join(TIMEOUT)

        # Ensure data was processed.
        self.assertEqual(queue.get()['payload'], test_data)
Exemple #4
0
    def test_queuedlistener_enqueue(self):
        """Test %s QueuedListener() multiprocess enqueue functionality."""

        # NOTE: QueuedListener is designed to run on a separate
        #       process. The code run on that process is contained within the
        #       class. Exceptions encountered in that will not be caught or
        #       unit tested unless the code is tested directly in this process.
        #       However, the code has been made 'private' as it should not be
        #       called directly and it maintains a clean API. To properly
        #       unit-test this code, the 'private' mangling of the code will be
        #       dodged.

        # Create broadcaster.
        broadcaster = RawBroadcaster(self.Message.connection)

        # Abuse intention of 'private' mangling to get queuing function.
        fcn = QueuedListener._QueuedListener__enqueue
        queue = multiprocessing.Queue()

        # The '__enqueue' method does not reference 'self' so it can be tested
        # on this thread. However, it does block so multi-threading must be
        # used to terminate its operation.
        run_event = threading.Event()
        run_event.set()

        # Launch '__enqueue' method on a new thread.
        thread = threading.Thread(target=fcn,
                                  args=(QueuedListener(
                                      self.Message.connection), run_event,
                                        self.Message.connection, None, queue))
        thread.daemon = True
        thread.start()
        time.sleep(DELAY)

        # Publish data via broadcaster.
        test_data = 'test'
        broadcaster.publish(test_data)
        time.sleep(DELAY)

        # Wait for thread to close.
        run_event.clear()
        thread.join(TIMEOUT)

        # Ensure data was processed.
        self.assertEqual(queue.get()['payload'], test_data)
Exemple #5
0
    def test_factory(self):
        """Test %s RawBroadcaster() from connection."""

        # Manufacture an instance of RawBroadcaster() from the connection
        # object.
        broadcaster = RawBroadcaster(self.connection)
        broadcaster.close()

        # Ensure errors are propagated.
        with self.assertRaises(Exception):
            RawBroadcaster(self.bad_connection)

        # Test instantiation fails if input is not a 'connection' object.
        with self.assertRaises(TypeError):
            RawBroadcaster('connection')
Exemple #6
0
    def test_log_raw(self):
        """Test LogConnection() log raw data."""

        self.log_file(os.path.join(TMP_PATH, 'unittest'), Connection(URL_C),
                      RawBroadcaster(Connection(URL_C)), 'test')