Exemple #1
0
    def test_stop_load_data_with_loading_status(self, mock_stat):
        """Test stop load data with status is loading."""
        class _MockStat:
            def __init__(self, _):
                self.st_ctime = 1
                self.st_mtime = 1
                self.st_size = 1

        mock_stat.side_effect = _MockStat

        manager = ExplainManager('./summary_dir')
        manager.status = _ExplainManagerStatus.LOADING.value
        loader_count = 3
        for i in range(loader_count):
            loader = ExplainLoader(f'./summary_dir{i}', f'./summary_dir{i}')
            loader.status = _LoaderStatus.LOADING.value
            manager._loader_pool[i] = loader

        def _wrapper(loader_manager):
            assert loader_manager.status == _ExplainManagerStatus.LOADING.value
            time.sleep(0.01)
            loader_manager.status = _ExplainManagerStatus.DONE.value
        thread = threading.Thread(target=_wrapper, args=(manager,), daemon=True)
        thread.start()
        manager._stop_load_data()
        for loader in manager._loader_pool.values():
            assert loader.status == _LoaderStatus.STOP.value
        assert manager.status == _ExplainManagerStatus.DONE.value
Exemple #2
0
    def test_stop(self, mock_stat, mock_is_file, mock_list_dir,
                  mock_list_events):
        """Test stop function."""
        mock_is_file.return_value = True
        mock_list_dir.return_value = ['events.summary.123.host_explain']
        mock_list_events.return_value = (True, False, None)

        class _MockStat:
            def __init__(self, _):
                self.st_ctime = 1
                self.st_mtime = 1
                self.st_size = 1

        mock_stat.side_effect = _MockStat

        loader = ExplainLoader(loader_id='./summary_dir',
                               summary_dir='./summary_dir')

        def _stop_loader(explain_loader):
            time.sleep(0.01)
            assert explain_loader.status == _LoaderStatus.LOADING.value
            explain_loader.stop()

        thread = threading.Thread(target=_stop_loader,
                                  args=[loader],
                                  daemon=True)
        thread.start()

        loader.load()
        assert loader.status == _LoaderStatus.STOP.value
    def test_loaded_with_is_end(self, mock_stat, mock_is_file, mock_list_dir, mock_list_events):
        """Test loading function."""
        mock_is_file.return_value = True
        mock_list_dir.return_value = ['events.summary.123.host_explain']
        mock_list_events.return_value = (True, True, None)

        mock_stat.side_effect = _MockStat

        loader = ExplainLoader(
            loader_id='./summary_dir',
            summary_dir='./summary_dir')

        loader.load()
        assert loader.status == _LoaderStatus.LOADED.value
 def _generate_loader_from_relative_path(
         self, relative_path: str) -> ExplainLoader:
     """Generate explain loader from the given relative path."""
     self._check_summary_exist(relative_path)
     current_dir = os.path.realpath(
         FileHandler.join(self._summary_base_dir, relative_path))
     loader_id = self._generate_loader_id(relative_path)
     loader = ExplainLoader(loader_id=loader_id, summary_dir=current_dir)
     return loader