コード例 #1
0
ファイル: test_worker.py プロジェクト: audip/lunr
class TestStatsRestoreProcess(unittest.TestCase):
    def setUp(self):
        self.cinder = MockCinder()
        self.scratch = mkdtemp()
        self.stats_path = os.path.join(self.scratch, 'stats')
        self.stat_queue = multiprocessing.Queue()
        with JsonLockFile(self.stats_path) as lock:
            self.stats_lock = lock
        self.volume_id = 'volume_id'
        self.block_count = 10
        self.process = StatsRestoreProcess(
            self.cinder, self.volume_id, self.stat_queue,
            self.block_count, self.stats_lock, update_interval=1)
        self.process.start()

    def tearDown(self):
        rmtree(self.scratch)
        self.assertFalse(self.process.is_alive())

    def test_restored(self):
        blocks_restored = 3
        for i in xrange(blocks_restored):
            task = ('restored', 1)
            self.stat_queue.put(task)
        self.stat_queue.put(None)
        while self.process.is_alive():
            sleep(0.1)
        with open(self.stats_path) as f:
            stats = json.loads(f.read())
            self.assertEqual(stats['block_count'], self.block_count)
            self.assertEqual(stats['blocks_restored'], blocks_restored)
            percent = 3 * 100.0 / 10
            self.assertEqual(stats['progress'], percent)
コード例 #2
0
ファイル: test_worker.py プロジェクト: audip/lunr
 def setUp(self):
     self.cinder = MockCinder()
     self.scratch = mkdtemp()
     self.stats_path = os.path.join(self.scratch, 'stats')
     self.stat_queue = multiprocessing.Queue()
     with JsonLockFile(self.stats_path) as lock:
         self.stats_lock = lock
     self.volume_id = 'volume_id'
     self.block_count = 10
     self.process = StatsRestoreProcess(
         self.cinder, self.volume_id, self.stat_queue,
         self.block_count, self.stats_lock, update_interval=1)
     self.process.start()