Example #1
0
    def test_raw_server(self):
        class MyServer(ZMQServer):
            def handler(self, data):
                if data == b'error':
                    raise TestError
                return data

        for argname in ["dtype", "type", "positional"]:
            if argname == 'dtype':
                server = MyServer(port=None,
                                  dtype='raw',
                                  bind_address='tcp://127.0.0.1')
            elif argname == 'type':
                server = MyServer(port=None,
                                  type='raw',
                                  bind_address='tcp://127.0.0.1')
            elif argname == 'positional':
                server = MyServer(None, 'raw', bind_address='tcp://127.0.0.1')
            try:
                self.assertIsInstance(server.context, SecureContext)
                response = zmq_get_raw(server.port, data=b'hello!')
                self.assertEqual(response, b'hello!')

                # Ignore the exception in the other thread:
                clientserver.raise_exception_in_thread = lambda *args: None
                try:
                    self.assertIn(b'TestError',
                                  zmq_get_raw(server.port, data=b'error'))
                finally:
                    clientserver.raise_exception_in_thread = \
                        raise_exception_in_thread
            finally:
                server.shutdown()
Example #2
0
 def transition_to_manual(self):
     if not self.use_zmq:
         return self.transition_to_manual_sockets(self.host, self.port)
     response = zprocess.zmq_get_raw(self.port, self.host, 'done')
     if response != 'ok':
         raise Exception('invalid response from server: ' + str(response))
     response = zprocess.zmq_get_raw(self.port, self.host, timeout=10)
     if response != 'done':
         raise Exception('invalid response from server: ' + str(response))
     return True  # indicates success
Example #3
0
 def transition_to_buffered(self, device_name, h5file, initial_values, fresh):
     h5file = shared_drive.path_to_agnostic(h5file)
     if not self.use_zmq:
         return self.transition_to_buffered_sockets(h5file,self.host, self.port)
     response = zprocess.zmq_get_raw(self.port, self.host, data=h5file)
     if response != 'ok':
         raise Exception('invalid response from server: ' + str(response))
     response = zprocess.zmq_get_raw(self.port, self.host, timeout = 10)
     if response != 'done':
         raise Exception('invalid response from server: ' + str(response))
     return {} # indicates final values of buffered run, we have none
Example #4
0
 def abort(self):
     if not self.use_zmq:
         return self.abort_sockets(self.host, self.port)
     response = zprocess.zmq_get_raw(self.port, self.host, 'abort')
     if response != 'done':
         raise Exception('invalid response from server: ' + str(response))
     return True  # indicates success
Example #5
0
 def update_settings_and_check_connectivity(self, host, use_zmq):
     self.host = host
     self.use_zmq = use_zmq
     if not self.host:
         return False
     if not self.use_zmq:
         return self.initialise_sockets(self.host, self.port)
     else:
         response = zprocess.zmq_get_raw(self.port, self.host, data='hello')
         if response == 'hello':
             return True
         else:
             raise Exception('invalid response from server: ' + str(response))