Esempio n. 1
0
    def test_context_resume(self, mock_file):
        mock_file.side_effect = self.side_effect
        agent1 = "127.0.0.1:1010"
        agent2 = "127.0.0.2:1010"
        context = Context(self.mock_server_config)
        task1 = context.pop(agent1)
        task2 = context.pop(agent2)
        context.running(agent1)
        self.mock_server_config.save_context(self.mock_server_config, context)
        mock_file.assert_any_call('fake/run/current.trace', "wb")

        restored_ctx = Context.create(self.mock_server_config)
        self.assertEqual(context.cstage_name, restored_ctx.cstage_name)
        self.assertEqual(len(context.stage_list), len(restored_ctx.stage_list))
        self.assertEqual(0, len(restored_ctx.active))
        self.assertEqual(context.reports_path, restored_ctx.reports_path)
        self.assertEqual(2, len(restored_ctx.pending))
        rtask1 = restored_ctx.pop(agent1)
        self.assertEqual(task1, rtask1)
        self.assertEqual(1, len(restored_ctx.active))
        rtask2 = restored_ctx.pop(agent2)
        self.assertEqual(task2, rtask2)
        self.assertEqual(2, len(restored_ctx.active))
        self.assertIsNotNone(restored_ctx._lock)
        restored_ctx.completed(agent1)
        restored_ctx.completed(agent2)
        _ = restored_ctx.pop(agent1)
        restored_ctx.completed(agent1)
        restored_ctx.completed(agent2)
        nstages, pending, completion = restored_ctx.ctx_status()[0]
        self.assertEqual(3, nstages)
        self.assertEqual(0, pending)
        self.assertEqual("66.67%", completion)
        self.assertEqual("stage1", restored_ctx.cstage_name)
Esempio n. 2
0
 def test_create(self, os_stat):
     os_stat.return_value = Mock(st_size=0)
     ctx = Context.create(self.mock_server_config)
     self.assertIsNotNone(ctx)
Esempio n. 3
0
 def __init__(self, *args, options, **kwargs):
     self._terminate = threading.Event()
     self.options = options
     self.ctx = Context.create(options)
     super().__init__(*args, **kwargs)