Francesco Romani has uploaded a new change for review. Change subject: tests: HostStatsThread: sampling window tests ......................................................................
tests: HostStatsThread: sampling window tests Add test to ensure that the circular buffer for Host samples works as intended. Change-Id: If97234d3df93b3b67ace7e3e0eb0df3e5e545776 Signed-off-by: Francesco Romani <[email protected]> --- M tests/samplingTests.py 1 file changed, 45 insertions(+), 0 deletions(-) git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/78/41878/1 diff --git a/tests/samplingTests.py b/tests/samplingTests.py index a8f6028..696ada3 100644 --- a/tests/samplingTests.py +++ b/tests/samplingTests.py @@ -263,6 +263,51 @@ self._hs = sampling.HostStatsThread(self.log) self.assertEquals(self._hs.get(), expected) + def testSamplesWraparound(self): + NUM = sampling.HostStatsThread.AVERAGING_WINDOW + 1 + + class FakeEvent(object): + def __init__(self, *args): + self.counter = 0 + + def isSet(self): + return self.counter >= NUM + + def set(self): + pass + + def wait(self, unused): + self.counter += 1 + + class FakeHostSample(object): + + _COUNTER = 0 + + def __repr__(self): + return "FakeHostSample(id=%i)" % self.id + + def __init__(self, *args): + self.id = FakeHostSample._COUNTER + FakeHostSample._COUNTER += 1 + + def to_connlog(self): + pass + + def connlog_diff(self, *args): + pass + + with MonkeyPatchScope([(sampling, 'HostSample', FakeHostSample)]): + self._hs = sampling.HostStatsThread(self.log) + self._hs._sampleInterval = 0 + # we cannot monkey patch, it will interfer on threading internals + self._hs._stopEvent = FakeEvent() + self._hs.start() + self._hs.join() + first, last = self._hs._samples[0], self._hs._samples[-1] + self.assertEqual(first.id, 1) + self.assertEqual(last.id, + sampling.HostStatsThread.AVERAGING_WINDOW) + class StatsCacheTests(TestCaseBase): -- To view, visit https://gerrit.ovirt.org/41878 To unsubscribe, visit https://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: If97234d3df93b3b67ace7e3e0eb0df3e5e545776 Gerrit-PatchSet: 1 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Francesco Romani <[email protected]> _______________________________________________ vdsm-patches mailing list [email protected] https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches
