From 6746607a578eca3383ade7fe7a88c39612f4d6e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isma=C3=ABl=20Bouya?= Date: Mon, 27 Aug 2018 11:21:18 +0200 Subject: Stop when portfolio worker is down and data is not fetched --- tests/test_store.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'tests') diff --git a/tests/test_store.py b/tests/test_store.py index 4ab9bdf..6f220c8 100644 --- a/tests/test_store.py +++ b/tests/test_store.py @@ -1379,11 +1379,19 @@ class PortfolioTest(WebMockTestCase): with self.subTest(worker=False): market.Portfolio.data = store.LockedVar(None) market.Portfolio.worker = mock.Mock() + market.Portfolio.worker_started = True is_worker.return_value = False market.Portfolio.get_cryptoportfolio() notify.assert_called_once_with() parse_cryptoportfolio.assert_not_called() store_cryptoportfolio.assert_not_called() + with self.subTest(worker_started=False): + market.Portfolio.data = store.LockedVar(None) + market.Portfolio.worker = mock.Mock() + market.Portfolio.worker_started = False + is_worker.return_value = False + with self.assertRaises(Exception): + market.Portfolio.get_cryptoportfolio() def test_parse_cryptoportfolio(self): with self.subTest(description="Normal case"): @@ -1649,6 +1657,22 @@ class PortfolioTest(WebMockTestCase): store.Portfolio.worker.join() self.assertFalse(store.Portfolio.worker.is_alive()) + with self.subTest("overdue"),\ + mock.patch.object(store.Portfolio, "get_cryptoportfolio") as get,\ + mock.patch.object(store.Portfolio, "report") as report,\ + mock.patch.object(store.Portfolio, "next_wait_time") as wait,\ + mock.patch.object(store.time, "sleep") as sleep: + wait.side_effect = Exception("Time over") + store.Portfolio.start_worker() + + store.Portfolio.worker_notify.set() + + store.Portfolio.callback.wait() + + report.print_log.assert_called_once_with("[Worker] Fetching cryptoportfolio") + get.assert_called_once_with(refetch=True) + self.assertFalse(store.Portfolio.worker.is_alive()) + def test_notify_and_wait(self): with mock.patch.object(store.Portfolio, "callback") as callback,\ mock.patch.object(store.Portfolio, "worker_notify") as worker_notify: -- cgit v1.2.3