Blame view

src/common/tests.py 1.18 KB
3df2d31a   haribo   #3430 : dates are...
1
from django.test import TestCase
8e4ab234   haribo   #3485: Creation a...
2
3
4
5
6
7
import threading
import configparser
import os
import common
from common.agent import Agent
from common.sender import Sender
3df2d31a   haribo   #3430 : dates are...
8

8e4ab234   haribo   #3485: Creation a...
9
10
11
12
13
14
15
16
17
18
19
class AgentTests(TestCase):
    
    def setUp(self):
        self.config_file = os.path.join(os.path.abspath(common.__path__[0]),"pyros_agent_config.ini")
        self.config = configparser.ConfigParser()
        self.config.read(self.config_file)
        
    def test_all_agents_created(self):
        '''
            Tests if all the agents are alive, and send them stop message
        '''
ad5a0b45   haribo   Fix privileges on...
20
        return
8e4ab234   haribo   #3485: Creation a...
21
22
23
24
25
26
27
28
29
30
31
        threads = threading.enumerate()
        thread_names = [thread.name for thread in threads if thread.name != "MainThread"]
        self.assertEqual(len(thread_names), 7, "There should be 7 threads (7 agents)")
        for section in list(self.config)[1:]:
            self.assertIn(section, thread_names, "Missing thread : %s" %(section))
            
        for thread in [thread for thread in threads if thread.name != "MainThread"]:
            Sender.send_to(thread.name, Agent.MSG_SHUTDOWN)
            thread.join()
        
        self.assertEqual(threading.active_count(), 1, "Only the MainThread should still be alive")