Beispiel #1
0
    def test_managed_cloud_datastore_emulator_creates_missing_data_dir(self):
        self.exit_stack.enter_context(self.swap_popen())

        rmtree_counter, makedirs_counter = self.exit_stack.enter_context(
            self.swap_managed_cloud_datastore_emulator_io_operations(False))
        self.exit_stack.enter_context(
            self.swap_to_always_return(common, 'wait_for_port_to_be_in_use'))

        self.exit_stack.enter_context(
            servers.managed_cloud_datastore_emulator())
        self.exit_stack.close()

        self.assertEqual(rmtree_counter.times_called, 0)
        self.assertEqual(makedirs_counter.times_called, 1)
Beispiel #2
0
    def test_managed_cloud_datastore_emulator_acknowledges_data_dir(self):
        popen_calls = self.exit_stack.enter_context(self.swap_popen())

        rmtree_counter, makedirs_counter = self.exit_stack.enter_context(
            self.swap_managed_cloud_datastore_emulator_io_operations(True))
        self.exit_stack.enter_context(
            self.swap_to_always_return(common, 'wait_for_port_to_be_in_use'))

        self.exit_stack.enter_context(
            servers.managed_cloud_datastore_emulator(clear_datastore=False))
        self.exit_stack.close()

        self.assertNotIn('--no-store-on-disk', popen_calls[0].program_args)

        self.assertEqual(rmtree_counter.times_called, 0)
        self.assertEqual(makedirs_counter.times_called, 0)
Beispiel #3
0
    def test_managed_cloud_datastore_emulator(self):
        popen_calls = self.exit_stack.enter_context(self.swap_popen())

        self.exit_stack.enter_context(
            self.swap_managed_cloud_datastore_emulator_io_operations(True))
        self.exit_stack.enter_context(
            self.swap_to_always_return(common, 'wait_for_port_to_be_in_use'))

        self.exit_stack.enter_context(
            servers.managed_cloud_datastore_emulator())
        self.exit_stack.close()

        self.assertEqual(len(popen_calls), 1)
        self.assertIn('beta emulators datastore start',
                      popen_calls[0].program_args)
        self.assertEqual(popen_calls[0].kwargs, {'shell': True})
def main(args=None):
    """Runs lighthouse checks and deletes reports."""
    parsed_args = _PARSER.parse_args(args=args)

    if parsed_args.mode == LIGHTHOUSE_MODE_ACCESSIBILITY:
        lighthouse_mode = LIGHTHOUSE_MODE_ACCESSIBILITY
        server_mode = SERVER_MODE_DEV
    elif parsed_args.mode == LIGHTHOUSE_MODE_PERFORMANCE:
        lighthouse_mode = LIGHTHOUSE_MODE_PERFORMANCE
        server_mode = SERVER_MODE_PROD
    else:
        raise Exception('Invalid parameter passed in: \'%s\', please choose'
                        'from \'accessibility\' or \'performance\'' %
                        parsed_args.mode)

    if lighthouse_mode == LIGHTHOUSE_MODE_PERFORMANCE:
        python_utils.PRINT('Building files in production mode.')
        build.main(args=['--prod_env'])
    elif lighthouse_mode == LIGHTHOUSE_MODE_ACCESSIBILITY:
        build.main(args=[])
        run_webpack_compilation()

    with contextlib.ExitStack() as stack:
        stack.enter_context(
            common.inplace_replace_file_context(
                common.CONSTANTS_FILE_PATH, '"ENABLE_ACCOUNT_DELETION": .*',
                '"ENABLE_ACCOUNT_DELETION": true,'))
        stack.enter_context(servers.managed_redis_server())
        stack.enter_context(servers.managed_elasticsearch_dev_server())

        if constants.EMULATOR_MODE:
            stack.enter_context(servers.managed_firebase_auth_emulator())
            stack.enter_context(servers.managed_cloud_datastore_emulator())

        stack.enter_context(
            servers.managed_dev_appserver(APP_YAML_FILENAMES[server_mode],
                                          port=GOOGLE_APP_ENGINE_PORT,
                                          log_level='critical',
                                          skip_sdk_update_check=True))

        run_lighthouse_puppeteer_script()
        run_lighthouse_checks(lighthouse_mode, parsed_args.shard)
Beispiel #5
0
def run_tests(args):
    """Run the scripts to start end-to-end tests."""
    if is_oppia_server_already_running():
        sys.exit(1)

    install_third_party_libraries(args.skip_install)

    with contextlib.ExitStack() as stack:
        dev_mode = not args.prod_env

        if args.skip_build:
            build.modify_constants(prod_env=args.prod_env)
        else:
            build_js_files(dev_mode, source_maps=args.source_maps)
        stack.callback(build.set_constants_to_default)

        stack.enter_context(servers.managed_redis_server())
        stack.enter_context(servers.managed_elasticsearch_dev_server())
        if constants.EMULATOR_MODE:
            stack.enter_context(servers.managed_firebase_auth_emulator())
            stack.enter_context(
                servers.managed_cloud_datastore_emulator(clear_datastore=True))

        app_yaml_path = 'app.yaml' if args.prod_env else 'app_dev.yaml'
        stack.enter_context(
            servers.managed_dev_appserver(
                app_yaml_path,
                port=GOOGLE_APP_ENGINE_PORT,
                log_level=args.server_log_level,
                # Automatic restart can be disabled since we don't expect code
                # changes to happen while the e2e tests are running.
                automatic_restart=False,
                skip_sdk_update_check=True,
                env={
                    **os.environ,
                    'PORTSERVER_ADDRESS':
                    common.PORTSERVER_SOCKET_FILEPATH,
                }))

        stack.enter_context(
            servers.managed_webdriver_server(
                chrome_version=args.chrome_driver_version))

        proc = stack.enter_context(
            servers.managed_protractor_server(
                suite_name=args.suite,
                dev_mode=dev_mode,
                debug_mode=args.debug_mode,
                sharding_instances=args.sharding_instances,
                stdout=subprocess.PIPE))

        print('Servers have come up.\n'
              'Note: If ADD_SCREENSHOT_REPORTER is set to true in '
              'core/tests/protractor.conf.js, you can view screenshots of the '
              'failed tests in ../protractor-screenshots/')

        output_lines = []
        while True:
            # Keep reading lines until an empty string is returned. Empty
            # strings signal that the process has ended.
            for line in iter(proc.stdout.readline, b''):
                if isinstance(line, str):
                    # Although our unit tests always provide unicode strings,
                    # the actual server needs this failsafe since it can output
                    # non-unicode strings.
                    line = line.encode('utf-8')  # pragma: no cover
                output_lines.append(line.rstrip())
                # Replaces non-ASCII characters with '?'.
                common.write_stdout_safe(line.decode('ascii',
                                                     errors='replace'))
            # The poll() method returns None while the process is running,
            # otherwise it returns the return code of the process (an int).
            if proc.poll() is not None:
                break

        return output_lines, proc.returncode