Commit 7066c2d8 authored by Marco Buttu's avatar Marco Buttu
Browse files

Regression test for issue #143

parent 67abaceb
Loading
Loading
Loading
Loading
+28 −14
Original line number Diff line number Diff line
"""Issue https://github.com/discos/discos/issues/143"""
"""Test issue https://github.com/discos/discos/issues/143"""

import os
import time
import unittest
from subprocess import Popen, PIPE
from Acspy.Clients.SimpleClient import PySimpleClient
from testing.containers import Container


__author__ = "Marco Buttu <mbuttu@oa-cagliari.inaf.it>"


class TestContainerCrash(unittest.TestCase):

    telescope = os.getenv('STATION')

    @classmethod
    def setUpClass(cls):
        cls.containers = [
            Container('MinorServoContainer', 'cpp'),
        ]


    def setUp(self):
        self.client = PySimpleClient()
        for container in self.containers:
            container.start()
            container.wait_until_running()
            if not container.is_running():
                self.fail('cannot run %s' % container.name)

    def tearDown(self):
        self.client.disconnect()
        for container in self.containers:
            container.stop()
    
    def test_get_and_release_component(self):
        """The container must be alive after releasing the component"""
        client = PySimpleClient()
        srp = client.getComponent('MINORSERVO/SRP')
        pipes = Popen(['acsContainersStatus'], stdout=PIPE, stderr=PIPE)
        out, err = pipes.communicate()
        expected_regex = 'MinorServoContainer container is running'
        self.assertRegexpMatches(out, expected_regex)

        client.releaseComponent('MINORSERVO/SRP')
        time.sleep(1)
        pipes = Popen(['acsContainersStatus'], stdout=PIPE, stderr=PIPE)
        out, err = pipes.communicate()
        expected_regex = 'MinorServoContainer container is running'
        self.assertRegexpMatches(out, expected_regex)
        srp = self.client.getComponent('MINORSERVO/SRP')
        self.client.releaseComponent('MINORSERVO/SRP')
        time.sleep(3)
        for container in self.containers:
            self.assertTrue(container.is_running())

        
if __name__ == '__main__':