<commit_before>from common_fixtures import *  # NOQA


def _process_names(processes):
    return set([x.processName for x in processes])


def test_container_ha_default(client, super_client, user_sim_context):
    c = client.create_container(imageUuid=user_sim_context['imageUuid'],
                                requestedHostId=user_sim_context['host'].id,
                                name='simForgetImmediately')
    c = client.wait_success(c)
    assert c.state == 'running'

    def do_ping():
        ping = one(super_client.list_task, name='agent.ping')
        ping.execute()

    def callback():
        processes = process_instances(super_client, c, type='instance')
        if 'instance.stop' not in _process_names(processes):
            do_ping()
            return None
        return processes

    processes = wait_for(callback)

    c = client.wait_success(c)
    assert c.state == 'stopped'

    assert _process_names(processes) == set(['instance.create',
                                             'instance.stop'])


def test_container_ha_stop(super_client, sim_context):
    c = super_client.create_container(imageUuid=sim_context['imageUuid'],
                                      requestedHostId=sim_context['host'].id,
                                      instanceTriggeredStop='stop',
                                      systemContainer='NetworkAgent',
                                      data={'simForgetImmediately': True})
    c = super_client.wait_success(c)
    assert c.state == 'running'

    def do_ping():
        ping = one(super_client.list_task, name='agent.ping')
        ping.execute()

    def callback():
        processes = process_instances(super_client, c, type='instance')
        if 'instance.stop' not in _process_names(processes):
            do_ping()
            return None
        return processes

    processes = wait_for(callback)

    c = super_client.wait_success(c)
    assert c.state == 'stopped'

    assert _process_names(processes) == set(['instance.create',
                                             'instance.restart',
                                             'instance.stop'])

<commit_msg>Dont assert initial state on ha tests.<commit_after>from common_fixtures import *  # NOQA


def _process_names(processes):
    return set([x.processName for x in processes])


def test_container_ha_default(client, super_client, user_sim_context):
    c = client.create_container(imageUuid=user_sim_context['imageUuid'],
                                requestedHostId=user_sim_context['host'].id,
                                name='simForgetImmediately')
    c = client.wait_success(c)

    def do_ping():
        ping = one(super_client.list_task, name='agent.ping')
        ping.execute()

    def callback():
        processes = process_instances(super_client, c, type='instance')
        if 'instance.stop' not in _process_names(processes):
            do_ping()
            return None
        return processes

    processes = wait_for(callback)

    c = client.wait_success(c)
    assert c.state == 'stopped'

    assert _process_names(processes) == set(['instance.create',
                                             'instance.stop'])


def test_container_ha_stop(super_client, sim_context):
    c = super_client.create_container(imageUuid=sim_context['imageUuid'],
                                      requestedHostId=sim_context['host'].id,
                                      instanceTriggeredStop='stop',
                                      systemContainer='NetworkAgent',
                                      data={'simForgetImmediately': True})
    c = super_client.wait_success(c)

    def do_ping():
        ping = one(super_client.list_task, name='agent.ping')
        ping.execute()

    def callback():
        processes = process_instances(super_client, c, type='instance')
        if 'instance.stop' not in _process_names(processes):
            do_ping()
            return None
        return processes

    processes = wait_for(callback)

    c = super_client.wait_success(c)
    assert c.state == 'stopped'

    assert _process_names(processes) == set(['instance.create',
                                             'instance.restart',
                                             'instance.stop'])


{'fraction_non_alphanumeric': 0.09858501507770819, 'fraction_numerical': 0.0, 'mean_word_length': 1.9902912621359223, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 20, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5704618', 'n_tokens_mistral': 1156, 'n_tokens_neox': 1114, 'n_words': 214}