示例#1
0
    def test_persist_option_and_persisted_sections(self, parser, mocker,
                                                   monkeypatch):
        time_time = 1000
        time_delta = 50
        monkeypatch.setattr(time, "time", lambda: time_time)
        monkeypatch.setattr(
            SectionStore,
            "load",
            lambda self: PersistedSections({
                SectionName("persisted"): (42, 69, [["content"]]),
            }),
        )
        # Patch IO:
        monkeypatch.setattr(SectionStore, "store", lambda self, sections: None)

        raw_data = AgentRawData(b"\n".join((
            b"<<<section:persist(%i)>>>" % (time_time + time_delta),
            b"first line",
            b"second line",
        )))

        ahs = parser.parse(raw_data, selection=NO_SELECTION)

        assert ahs.sections == {
            SectionName("section"): [["first", "line"], ["second", "line"]],
            SectionName("persisted"): [["content"]],
        }
        assert ahs.cache_info == {
            SectionName("section"): (time_time, time_delta),
            SectionName("persisted"): (42, 27),
        }
        assert ahs.piggybacked_raw_data == {}
示例#2
0
    def test_update_with_empty_store_and_persisted(self, host_sections, logger):
        sections: Mapping[SectionName, ABCRawDataSection] = {}
        section_store = MockStore(PersistedSections({}))

        host_sections.add_persisted_sections(
            sections,
            section_store=section_store,
            fetch_interval=lambda section_name: 0,
            now=0,
            keep_outdated=True,
            logger=logger,
        )

        assert not host_sections.sections
示例#3
0
    def test_update_with_empty_store(self, host_sections, logger):
        fresh = SectionName("fresh")

        sections: Mapping[SectionName, ABCRawDataSection] = {fresh: [[""]]}
        section_store = MockStore(PersistedSections({}))

        host_sections.add_persisted_sections(
            sections,
            section_store=section_store,
            fetch_interval=lambda section_name: 0,
            now=0,
            keep_outdated=True,
            logger=logger,
        )

        assert fresh in host_sections.sections
示例#4
0
    def test_do_not_keep_outdated(self, host_sections, logger):
        stored = SectionName("stored")

        sections: Mapping[SectionName, ABCRawDataSection] = {}
        section_store = MockStore(PersistedSections({stored: (0, 0, [])}))

        host_sections.add_persisted_sections(
            sections,
            section_store=section_store,
            fetch_interval=lambda section_name: 0,
            now=1,
            keep_outdated=False,
            logger=logger,
        )

        assert not host_sections.sections
示例#5
0
    def test_with_persisted_sections(self, parser, sections, monkeypatch):
        monkeypatch.setattr(time, "time", lambda: 1000)
        monkeypatch.setattr(parser, "check_intervals", defaultdict(lambda: 33))
        monkeypatch.setattr(
            SectionStore, "load", lambda self: PersistedSections({
                SectionName("persisted"): (42, 69, [["content"]]),
            }))
        # Patch IO:
        monkeypatch.setattr(SectionStore, "store", lambda self, sections: None)

        raw_data = sections

        ahs = parser.parse(raw_data, selection=NO_SELECTION)
        all_sections = sections.copy()
        all_sections[SectionName("persisted")] = [["content"]]
        assert ahs.sections == all_sections
        assert ahs.cache_info == {SectionName("persisted"): (42, 27)}
        assert ahs.piggybacked_raw_data == {}
示例#6
0
    def test_update_store_with_newest(self, host_sections, logger):
        section = SectionName("section")

        sections = {section: [["newest"]]}
        section_store = MockStore(PersistedSections({
            section: (0, 0, [["oldest"]]),
        }))

        host_sections.add_persisted_sections(
            sections,
            section_store=section_store,
            fetch_interval=lambda section_name: 0,
            now=0,
            keep_outdated=True,
            logger=logger,
        )

        assert host_sections.sections[section] == [["newest"]]