<commit_before>#!/usr/bin/env python

import os
import subprocess as sp
import sys
import time

print('Building the image...')
sp.check_call(['bazel', 'run', '//:assemble-docker'])

print('Starting the image...')
sp.check_call(['docker', 'run', '-v', '{}:/grakn-core-all-linux/logs/'.format(os.getcwd()), '--name', 'grakn','-d', '--rm', '-ti', '-p', '127.0.0.1:48555:48555/tcp', 'bazel:assemble-docker'])
print('Docker status:')
sp.check_call(['docker', 'ps'])

sys.stdout.write('Waiting for the instance to be ready')
sys.stdout.flush()
timeout = 0 # TODO: add timeout
# TODO: fail if the docker image is dead
# upon a successful gRPC connection, the curl returns 0 in linux, and 8 in mac
while sp.call(['curl', '--output', '/dev/null', '--silent', '--head', '--fail', 'localhost:48555']) not in {0, 8}:
    sys.stdout.write('.')
    sys.stdout.flush()
    time.sleep(1)
print()

print('Running the test...')
sp.check_call(['bazel', 'test', '//test/common:grakn-application-test', '--test_output=streamed',
                          '--spawn_strategy=standalone', '--cache_test_results=no'])

print('Stopping the container...')
sp.check_call(['docker', 'kill', 'grakn'])
print('Done!')<commit_msg>Fix Docker image test (#5846)<commit_after>#!/usr/bin/env python

import os
import socket
import subprocess as sp
import sys
import time


def wait_for_port(port, host='localhost', timeout=30.0):
    start_time = time.perf_counter()
    while True:
        try:
            with socket.create_connection((host, port), timeout=timeout):
                break
        except OSError as ex:
            time.sleep(0.01)
            if time.perf_counter() - start_time >= timeout:
                raise TimeoutError('Waited too long for the port {} on host {} to start accepting '
                                   'connections.'.format(port, host)) from ex


print('Building the image...')
sp.check_call(['bazel', 'run', '//:assemble-docker'])

print('Starting the image...')
sp.check_call(['docker', 'run', '-v', '{}:/grakn-core-all-linux/logs/'.format(os.getcwd()), '--name', 'grakn','-d', '--rm', '-ti', '-p', '127.0.0.1:48555:48555/tcp', 'bazel:assemble-docker'])
print('Docker status:')
sp.check_call(['docker', 'ps'])

sys.stdout.write('Waiting for the instance to be ready')
sys.stdout.flush()
timeout = 0 # TODO: add timeout
# TODO: fail if the docker image is dead
wait_for_port(48555)

print('Running the test...')
sp.check_call(['bazel', 'test', '//test/common:grakn-application-test', '--test_output=streamed',
                          '--spawn_strategy=standalone', '--cache_test_results=no'])

print('Stopping the container...')
sp.check_call(['docker', 'kill', 'grakn'])
print('Done!')
{'fraction_non_alphanumeric': 0.19799777530589543, 'fraction_numerical': 0.021876158694846125, 'mean_word_length': 3.611965811965812, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5660292', 'n_tokens_mistral': 962, 'n_tokens_neox': 885, 'n_words': 222}