Example #1
0
 def setUp(self):
     self.m = Master()
Example #2
0
class TestMaster(unittest.TestCase):
    def setUp(self):
        self.m = Master()

    def test_add_client(self):
        c = MockClient()
        self.m.add_client(c)
        self.assertEqual(c.received, ["# Welcome client 0"],
            'received welcome string from master')
        self.assertEqual(self.m.clients, { 0: c },
            'new client appears in clients list')

    def test_remove_client(self):
        c = MockClient()
        self.m.add_client(c)
        self.m.remove_client(0)

        self.assertEqual(self.m.clients, {},
            'client was removed')
        self.assertRaises(LegionError, self.m.remove_client, 420)

    def test_get_client(self):
        c = MockClient()
        self.m.add_client(c)
        self.m.get_client(0)

        self.assertEqual(self.m.get_client(0), c, 'client was gotten')
        self.assertRaises(LegionError, self.m.get_client, 420)

    def test_idle_clients(self):
        (p, i0, i1, b) = clients = [
            MockClient(id=0, status='paused'),
            MockClient(id=1, status='idle'),
            MockClient(id=3, status='idle'),
            MockClient(id=2, status='busy'),
        ]

        for c in clients:
            self.m.add_client(c)

        idle = self.m.idle_clients()

        self.assert_(i0 in idle)
        self.assert_(i1 in idle)
        self.assert_(p not in idle)
        self.assert_(b not in idle)

    def test_dispatch_idle_clients(self):
        pass