2020-11-17 17:04:28 +01:00
|
|
|
import logging
|
|
|
|
|
import mock
|
|
|
|
|
import time
|
|
|
|
|
from mock import Mock
|
|
|
|
|
from cryptoadvance.specter.util.checker import Checker
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_checker(caplog):
|
|
|
|
|
callback_mock = Mock()
|
|
|
|
|
caplog.set_level(logging.DEBUG)
|
2020-12-06 15:40:22 +01:00
|
|
|
checker = Checker(lambda: callback_mock(), period=0.01, desc="test")
|
2020-11-17 17:04:28 +01:00
|
|
|
checker.start()
|
2020-11-17 23:30:00 +01:00
|
|
|
time.sleep(
|
|
|
|
|
0.1
|
|
|
|
|
) # If the above assumptions are failing, you might want to increase this
|
2020-12-06 15:40:22 +01:00
|
|
|
assert "Checker test started" in caplog.text
|
2020-11-17 17:04:28 +01:00
|
|
|
assert "This message won't show again until stopped and started." in caplog.text
|
|
|
|
|
checker.stop()
|
2022-12-02 04:04:37 -08:00
|
|
|
time.sleep(0.01)
|
2020-12-06 15:40:22 +01:00
|
|
|
assert "Checker test stopped" in caplog.text
|
2020-11-17 17:04:28 +01:00
|
|
|
callback_mock.side_effect = Exception("someException")
|
|
|
|
|
checker.start()
|
|
|
|
|
time.sleep(
|
2022-11-30 04:13:16 -08:00
|
|
|
2
|
2020-11-17 17:04:28 +01:00
|
|
|
) # If the above assumptions are failing, you might want to increase this
|
|
|
|
|
checker.stop()
|
|
|
|
|
assert "someException" in caplog.text
|
2020-11-19 16:21:20 +01:00
|
|
|
# should output 5 times
|
2022-12-09 20:15:54 +01:00
|
|
|
assert caplog.text.count("[ ERROR] Checker ") == 5
|
2022-11-30 04:13:16 -08:00
|
|
|
# But should also show stacktrace 5 times
|
|
|
|
|
assert caplog.text.count("Exception: someException") == 5
|
2022-12-02 04:04:37 -08:00
|
|
|
assert caplog.text.count("The above Error-Message is from now on suppressed!") == 1
|