Пример #1
0
    async def test_08_nested_add(self):
        sup_spec = AIOSpec(AIOSupervisor, [AIOSpec(DamagedWorker)])
        s = AIOSupervisor([sup_spec])
        await s.lifecycle.on_start()
        self.assertEqual(s.lifecycle.state, State.RUNNING)

        s2 = list(s.instances)[0]
        self.assertEqual(s2.lifecycle.state, State.RUNNING)

        await self.assertRaises(MaxRestarts, s2.add_child,
                                AIOSpec(BrokenWorker))
        self.assertEqual(s2.lifecycle.state, State.TERMINATED)
        self.assertEqual(s.lifecycle.state, State.TERMINATED)
Пример #2
0
    async def test_04_damaged_restart(self):
        s = await self.get_sup()
        await s.add_child(AIOSpec(DamagedWorker))
        workers = list(s.instances)
        self.assertEqual(len(workers), 2)
        worker2 = workers[1]
        self.assertEqual(s.state, State.RUNNING)
        self.assertEqual(worker2.lifecycle.state, State.RUNNING)

        await s.lifecycle.terminate()
        self.assertEqual(s.lifecycle.state, State.TERMINATED)
        self.assertEqual(len(s.instances), 0)
        self.assertEqual(workers[0].lifecycle.state, State.TERMINATED)
        self.assertEqual(workers[1].lifecycle.state, State.TERMINATED)
Пример #3
0
    async def test_02_restart(self):
        s = AIOSupervisor([AIOSpec(Worker)])
        await s.lifecycle.on_start()
        self.assertEqual(s.lifecycle.state, State.RUNNING)
        w = list(s.instances)[0]
        l = Linked()
        l.lifecycle.watch(w)
        self.assertEqual(l.notified, False)
        self.ensure_future(w.lifecycle.terminate())
        await asyncio.sleep(0.001)
        self.assertEqual(l.notified, True)
        self.assertEqual(w.lifecycle.state, State.TERMINATED)

        self.assertEqual(s.lifecycle.state, State.RUNNING)
Пример #4
0
 async def test_05_add_broken_worker(self):
     s = await self.get_sup()
     await self.assertRaises(MaxRestarts, s.add_child,
                             AIOSpec(BrokenWorker))
     self.assertEqual(s.lifecycle.state, State.TERMINATED)
Пример #5
0
 def __init__(self):
     self.specs = [AIOSpec(Worker)]
     super().__init__(self.specs)
Пример #6
0
 async def test_01_die_after_start(self):
     s = AIOSupervisor([AIOSpec(LaggyWorker)])
     await s.lifecycle.on_start()
     self.assertEqual(s.lifecycle.state, State.RUNNING)
     await asyncio.sleep(0.01)
     self.assertEqual(s.lifecycle.state, State.TERMINATED)
Пример #7
0
 async def test_07_supervisor_of_supervisor(self):
     sup_spec = AIOSpec(AIOSupervisor, [AIOSpec(BrokenWorker)])
     s = AIOSupervisor([sup_spec])
     await self.assertRaises(MaxRestarts, s.lifecycle.on_start)
     self.assertEqual(s.lifecycle.state, State.TERMINATED)
Пример #8
0
 async def test_06_broken_supervisor(self):
     s = AIOSupervisor([AIOSpec(BrokenWorker)])
     await self.assertRaises(MaxRestarts, s.lifecycle.on_start)
     self.assertEqual(list(s.instances), [])
     self.assertEqual(s.lifecycle.state, State.TERMINATED)