예제 #1
0
def test_server_running(
    force: bool = False,
    external_host: str = 'testserver',
    log_file: Optional[str] = None,
    dots: bool = False,
    use_db: bool = True,
) -> Iterator[None]:
    log = sys.stdout
    if log_file:
        if os.path.exists(log_file) and os.path.getsize(log_file) < 100000:
            log = open(log_file, 'a')
            log.write('\n\n')
        else:
            log = open(log_file, 'w')

    set_up_django(external_host)

    if use_db:
        update_test_databases_if_required(rebuild_test_database=True)

    # Run this not through the shell, so that we have the actual PID.
    run_dev_server_command = ['tools/run-dev.py', '--test', '--streamlined']
    if force:
        run_dev_server_command.append('--force')
    server = subprocess.Popen(run_dev_server_command, stdout=log, stderr=log)

    try:
        # Wait for the server to start up.
        sys.stdout.write('\nWaiting for test server (may take a while)')
        if not dots:
            sys.stdout.write('\n\n')
        t = time.time()
        while not server_is_up(server, log_file):
            if dots:
                sys.stdout.write('.')
                sys.stdout.flush()
            time.sleep(0.4)
            if time.time() - t > MAX_SERVER_WAIT:
                raise Exception('Timeout waiting for server')
        sys.stdout.write('\n\n--- SERVER IS UP! ---\n\n')

        # DO OUR ACTUAL TESTING HERE!!!
        yield

    finally:
        assert_server_running(server, log_file)
        server.terminate()
예제 #2
0
def test_server_running(
    skip_provision_check: bool = False,
    external_host: str = "testserver",
    log_file: Optional[str] = None,
    dots: bool = False,
) -> Iterator[None]:
    log = sys.stdout
    if log_file:
        if os.path.exists(log_file) and os.path.getsize(log_file) < 100000:
            log = open(log_file, "a")
            log.write("\n\n")
        else:
            log = open(log_file, "w")

    set_up_django(external_host)

    update_test_databases_if_required(rebuild_test_database=True)

    # Run this not through the shell, so that we have the actual PID.
    run_dev_server_command = ["tools/run-dev.py", "--test", "--streamlined"]
    if skip_provision_check:
        run_dev_server_command.append("--skip-provision-check")
    server = subprocess.Popen(run_dev_server_command, stdout=log, stderr=log)

    try:
        # Wait for the server to start up.
        sys.stdout.write("\nWaiting for test server (may take a while)")
        if not dots:
            sys.stdout.write("\n\n")
        t = time.time()
        while not server_is_up(server, log_file):
            if dots:
                sys.stdout.write(".")
                sys.stdout.flush()
            time.sleep(0.4)
            if time.time() - t > MAX_SERVER_WAIT:
                raise Exception("Timeout waiting for server")
        sys.stdout.write("\n\n--- SERVER IS UP! ---\n\n")

        # DO OUR ACTUAL TESTING HERE!!!
        yield

    finally:
        assert_server_running(server, log_file)
        server.terminate()
        server.wait()