Exemple #1
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