Beispiel #1
0
def run_mocked_mediator_current_thread(port):
    """
    How to run:

    python -c 'from brotab.tests.test_main import run_mocked_mediator_current_thread as run; run(4635)'
    """
    remote_api = DummyBrowserRemoteAPI()
    port = get_available_tcp_port() if port is None else port
    server = MediatorHttpServer(DEFAULT_HTTP_IFACE, port, remote_api, 0.050)
    server.run.here()
Beispiel #2
0
 def __init__(self, prefix='a', port=None, remote_api=None):
     self.port = get_available_tcp_port() if port is None else port
     self.transport = MockedLoggingTransport()
     self.remote_api = default_remote_api(
         self.transport) if remote_api is None else remote_api
     self.server = MediatorHttpServer(DEFAULT_HTTP_IFACE, self.port,
                                      self.remote_api, 0.050)
     self.thread = self.server.run.in_thread()
     self.transport.received_extend(['mocked'])
     self.api = SingleMediatorAPI(prefix, port=self.port, startup_timeout=1)
     assert self.api.browser == 'mocked'
     self.transport.reset()
Beispiel #3
0
 def __init__(self, prefix='a', port=None, remote_api=None):
     mediator_logger.info('starting mediator pid=%s', os.getpid())
     self.prefix = prefix
     self.port = get_available_tcp_port() if port is None else port
     input_r, input_w = os.pipe()
     output_r, output_w = os.pipe()
     self.transport_browser = transport_with_timeout(
         output_r, input_w, 0.050)
     self.transport_mediator = transport_with_timeout(
         input_r, output_w, 0.050)
     self.remote_api = default_remote_api(
         self.transport_mediator) if remote_api is None else remote_api
     self.server = MediatorHttpServer(DEFAULT_HTTP_IFACE,
                                      self.port,
                                      self.remote_api,
                                      poll_interval=0.050)
     self.thread = None
     self.api = None
Beispiel #4
0
    def run_as_child_process(self):
        port = get_available_tcp_port()
        mediator_logger.info('starting test pid=%s', os.getpid())

        def run_threaded_mediator():
            mediator = MockedPiperMediator(port=port)
            mediator.start()
            sig.setup(lambda: mediator.server.run.shutdown(join=False))
            mediator.join()

        mediator_process = Process(target=run_threaded_mediator)
        mediator_process.start()
        api = api_must_ready(port, 'mocked')

        yield mediator_process

        self.assertTrue(Waiter(api.pid_not_ready).wait(timeout=1.0))
        mediator_process.join()
Beispiel #5
0
    def test_when_parent_died(self):
        port = get_available_tcp_port()
        mediator_logger.info('starting test pid=%s', os.getpid())
        kill_parent = Barrier(2)

        def run_threaded_mediator():
            mediator = MockedPiperMediator(port=port)
            mediator.start()
            mediator.join()

        def run_doomed_parent_browser():
            mediator_logger.info('doomed_parent_browser pid=%s', os.getpid())
            mediator_process = Process(target=run_threaded_mediator)
            mediator_process.start()
            mediator_process.join()

        def on_sig_child(signum, frame):
            pid, status = os.wait()
            mediator_logger.info('reaped child signum=%s pid=%s status=%s',
                                 signum, pid, status)

        def run_supervisor():
            signal.signal(signal.SIGCHLD, on_sig_child)
            doomed_parent_browser = Process(target=run_doomed_parent_browser)
            doomed_parent_browser.start()
            kill_parent.wait()
            doomed_parent_browser.terminate()
            doomed_parent_browser.join()

        signal.signal(signal.SIGCHLD, on_sig_child)
        supervisor = Process(target=run_supervisor)
        supervisor.start()
        api = api_must_ready(port, 'mocked')

        # kill parent and expect mediator to terminate as well
        kill_parent.wait()
        self.assertTrue(Waiter(api.pid_not_ready).wait(timeout=1.0))
        supervisor.join()