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

"""
    Copyright (C) 2014 Pelagicore AB
    All rights reserved.
"""

from time import sleep
import os
import sys

from common import ComponentTestHelper


SLEEPY_APP = """
#!/bin/sh
sleep 1
"""

helper = ComponentTestHelper()


class TestAppShutdown():
    """ Test that Pelagicontain shuts down when the contained app does.

        Starts Pelagicontain with an app that sleeps and then exits. Asserts
        that the Pelagicontain process is not running in the system anymore after
        the app has exited.
    """

    def test_pelagicontain_shuts_down_when_app_does(
            self,
            pelagicontain_binary,
            container_path,
            teardown_fixture):
        """ * Start Pelagicontain
            * Launch the app
            * Make sure the app has time to exit by itself
            * Assert Pelagicontain is not running after the app has exited
        """
        self.create_app(container_path)
        helper.start_pelagicontain(pelagicontain_binary, container_path)
        helper.pelagicontain_iface().Launch(helper.app_id())
        # Sleep a little bit longer than the app
        sleep(2)
        assert not self.pelagicontain_is_running()

    def create_app(self, container_path):
        containedapp_file = container_path + "/com.pelagicore.comptest/bin/containedapp"
        with open(containedapp_file, "w") as f:
            print "Overwriting containedapp..."
            f.write(SLEEPY_APP)
        os.system("chmod 755 " + containedapp_file)

    def pelagicontain_is_running(self):
        """ Return False is Pelagicontain is not running, True if it is.
        """
        # If the process is a zombie it will be killed by this call, otherwise
        # it's unaffected
        helper.poke_pelagicontain_zombie()
        pc_pid = helper.pelagicontain_pid()
        try:
            os.kill(pc_pid, 0)
        except OSError:
            return False
        else:
            return True
<commit_msg>test_appshutdown.py: Give more time for container to shut down. This should help the tests not show false negatives in slower environments.<commit_after>#!/usr/bin/env python

"""
    Copyright (C) 2014 Pelagicore AB
    All rights reserved.
"""

from time import sleep
import os
import sys

from common import ComponentTestHelper


SLEEPY_APP = """
#!/bin/sh
sleep 1
"""

helper = ComponentTestHelper()


class TestAppShutdown():
    """ Test that Pelagicontain shuts down when the contained app does.

        Starts Pelagicontain with an app that sleeps and then exits. Asserts
        that the Pelagicontain process is not running in the system anymore after
        the app has exited.
    """

    def test_pelagicontain_shuts_down_when_app_does(
            self,
            pelagicontain_binary,
            container_path,
            teardown_fixture):
        """ * Start Pelagicontain
            * Launch the app
            * Make sure the app has time to exit by itself
            * Assert Pelagicontain is not running after the app has exited
        """
        self.create_app(container_path)
        helper.start_pelagicontain(pelagicontain_binary, container_path)
        helper.pelagicontain_iface().Launch(helper.app_id())
        # Sleep a little bit longer than the app
        sleep(4)
        assert not self.pelagicontain_is_running()

    def create_app(self, container_path):
        containedapp_file = container_path + "/com.pelagicore.comptest/bin/containedapp"
        with open(containedapp_file, "w") as f:
            print "Overwriting containedapp..."
            f.write(SLEEPY_APP)
        os.system("chmod 755 " + containedapp_file)

    def pelagicontain_is_running(self):
        """ Return False is Pelagicontain is not running, True if it is.
        """
        # If the process is a zombie it will be killed by this call, otherwise
        # it's unaffected
        helper.poke_pelagicontain_zombie()
        pc_pid = helper.pelagicontain_pid()
        try:
            os.kill(pc_pid, 0)
        except OSError:
            return False
        else:
            return True

{'fraction_non_alphanumeric': 0.07032007759456838, 'fraction_numerical': 0.004849660523763337, 'mean_word_length': 2.397858319604613, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4885056', 'n_tokens_mistral': 1244, 'n_tokens_neox': 1157, 'n_words': 368}