Ejemplo n.º 1
0
def test_start_and_stop():
    control = RaptorControlServer()

    assert control.server is None
    control.start()
    assert isinstance(control.server, HTTPServer)
    assert control.server.fileno()
    assert control._server_thread.is_alive()

    control.stop()
    assert not control._server_thread.is_alive()
Ejemplo n.º 2
0
def test_server_android_app_backgrounding():
    # Mock the background and foreground functions
    with mock.patch.object(RaptorControlServer,
                           "background_app",
                           return_value=True) as _, mock.patch.object(
                               RaptorControlServer,
                               "foreground_app",
                               return_value=True) as _:

        results_handler = RaptorResultsHandler()
        control = RaptorControlServer(results_handler)
        control.backgrounded = False

        control.start()
        assert control._server_thread.is_alive()

        def post_start_background():
            requests.post(
                "http://127.0.0.1:%s/" % control.port,
                json={
                    "type": "webext_start_background",
                    "data": "starting background app",
                },
            )

        def post_end_background():
            requests.post(
                "http://127.0.0.1:%s/" % control.port,
                json={
                    "type": "webext_end_background",
                    "data": "ending background app"
                },
            )

        # Test that app is backgrounded
        post_start_background()
        control.background_app.assert_called()

        # Test that app is returned to foreground
        post_end_background()
        control.foreground_app.assert_called()

        # Make sure the control server stops after these requests
        control.stop()
        assert not control._server_thread.is_alive()
Ejemplo n.º 3
0
 def start_control_server(self):
     self.control_server = RaptorControlServer()
     self.control_server.start()
Ejemplo n.º 4
0
class Raptor(object):
    """Container class for Raptor"""
    def __init__(self, app, binary):
        self.config = {}
        self.config['app'] = app
        self.config['binary'] = binary
        self.config['platform'] = mozinfo.os

        self.raptor_venv = os.path.join(os.getcwd(), 'raptor-venv')
        self.log = get_default_logger(component='raptor')
        self.control_server = None
        self.playback = None

        # Create the profile
        pref_file = os.path.join(here, 'preferences',
                                 '{}.json'.format(self.config['app']))
        prefs = {}
        if os.path.isfile(pref_file):
            with open(pref_file, 'r') as fh:
                prefs = json.load(fh)

        try:
            self.profile = create_profile(self.config['app'],
                                          preferences=prefs)
        except NotImplementedError:
            self.profile = None

        # Create the runner
        self.output_handler = OutputHandler()
        process_args = {
            'processOutputLine': [self.output_handler],
        }
        runner_cls = runners[app]
        self.runner = runner_cls(binary,
                                 profile=self.profile,
                                 process_args=process_args)

    def start_control_server(self):
        self.control_server = RaptorControlServer()
        self.control_server.start()

    def run_test(self, test, timeout=None):
        self.log.info("starting raptor test: %s" % test['name'])
        gen_test_config(self.config['app'], test['name'])

        self.profile.addons.install(os.path.join(webext_dir, 'raptor'))

        # some tests require tools to playback the test pages
        if test.get('playback', None) is not None:
            self.config['playback_tool'] = test.get('playback')
            self.log.info("test uses playback tool: %s " %
                          self.config['playback_tool'])
            self.playback = get_playback(self.config)
            self.playback.start()

        self.runner.start()

        first_time = int(time.time()) * 1000
        proc = self.runner.process_handler
        self.output_handler.proc = proc

        try:
            self.runner.wait(timeout)
        finally:
            try:
                self.runner.check_for_crashes()
            except NotImplementedError:  # not implemented for Chrome
                pass

        if self.playback is not None:
            self.playback.stop()

        if self.runner.is_running():
            self.log("Application timed out after {} seconds".format(timeout))
            self.runner.stop()

        proc.output.append(
            "__startBeforeLaunchTimestamp%d__endBeforeLaunchTimestamp" %
            first_time)
        proc.output.append(
            "__startAfterTerminationTimestamp%d__endAfterTerminationTimestamp"
            % (int(time.time()) * 1000))

    def process_results(self):
        self.log.info('todo: process results and dump in PERFHERDER_JSON blob')
        self.log.info('- or - do we want the control server to do that?')

    def clean_up(self):
        self.control_server.stop()
        self.runner.stop()
        self.log.info("raptor finished")