示例#1
0
 def test_signal_response_status(self):
     """
     Ensure there's an appropriate response from server when signaling.
     """
     sig = 4
     request = SignalRequest()
     request.event = sig
     request.content = 'my signal contents'
     request.mac_method = mac_auth.MacMethod.MAC_NONE
     request.mac = ""
     service = RpcService(EventsServerService_Stub, port, 'localhost')
     # test synch
     response = service.signal(request, timeout=1000)
     self.assertEqual(EventResponse.OK, response.status,
                      'Wrong response status.')
示例#2
0
    def test_client_receives_signal(self):
        """
        Ensure clients can receive signals.
        """
        sig = 7
        flag = Mock()

        events.register(sig, lambda req: flag(req.event))
        request = SignalRequest()
        request.event = sig
        request.content = ""
        request.mac_method = mac_auth.MacMethod.MAC_NONE
        request.mac = ""
        service = RpcService(EventsServerService_Stub, port, 'localhost')
        response = service.signal(request, timeout=1000)
        self.assertTrue(response is not None, 'Did not receive response.')
        time.sleep(0.5)
        flag.assert_called_once_with(sig)
示例#3
0
    def test_signal_executes_callback(self):
        """
        Ensure callback is executed upon receiving signal.
        """
        sig = CLIENT_UID
        request = SignalRequest()
        request.event = sig
        request.content = 'my signal contents'
        request.mac_method = mac_auth.MacMethod.MAC_NONE
        request.mac = ""
        service = RpcService(EventsServerService_Stub, port, 'localhost')

        # register a callback
        flag = Mock()
        events.register(sig, lambda req: flag(req.event))
        # signal
        response = service.signal(request)
        self.assertEqual(EventResponse.OK, response.status,
                         'Wrong response status.')
        time.sleep(1)  # wait for signal to arrive
        flag.assert_called_once_with(sig)
示例#4
0
    def test_signal_response_status(self):
        """
        Ensure there's an appropriate response from server when signaling.
        """
        sig = 4
        request = SignalRequest()
        request.event = sig
        request.content = 'my signal contents'
        request.mac_method = mac_auth.MacMethod.MAC_NONE
        request.mac = ""
        service = RpcService(EventsServerService_Stub, port, 'localhost')
        # test synch
        response = service.signal(request, timeout=1000)
        self.assertEqual(EventResponse.OK, response.status,
                         'Wrong response status.')
        # test asynch

        def local_callback(request, response):
            global local_callback_executed
            local_callback_executed = True

        events.register(sig, local_callback)
        service.signal(request, callback=local_callback)
        time.sleep(0.1)
        self.assertTrue(local_callback_executed,
                        'Local callback did not execute.')
示例#5
0
    def test_component_receives_signal(self):
        """
        Ensure components can receive signals.
        """
        sig = 7

        def getsig(param=None):
            global received
            received = True

        events.register(sig, getsig)
        request = SignalRequest()
        request.event = sig
        request.content = ""
        request.mac_method = mac_auth.MacMethod.MAC_NONE
        request.mac = ""
        service = RpcService(EventsServerService_Stub, port, 'localhost')
        response = service.signal(request, timeout=1000)
        self.assertTrue(response is not None, 'Did not receive response.')
        time.sleep(0.5)
        self.assertTrue(received, 'Did not receive signal back.')