[damned-lies] No need to use timezones in ModuleLock internals
- From: Claude Paroz <claudep src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [damned-lies] No need to use timezones in ModuleLock internals
- Date: Tue, 7 Dec 2021 17:40:23 +0000 (UTC)
commit 20000316d959509502e46b11e8546ad2f16abea2
Author: Claude Paroz <claude 2xlibre net>
Date: Tue Dec 7 18:39:49 2021 +0100
No need to use timezones in ModuleLock internals
stats/models.py | 2 +-
stats/tests/tests.py | 9 +++++++++
2 files changed, 10 insertions(+), 1 deletion(-)
---
diff --git a/stats/models.py b/stats/models.py
index 7ecc9efa..e95cdb93 100644
--- a/stats/models.py
+++ b/stats/models.py
@@ -203,7 +203,7 @@ class ModuleLock:
self.dirpath.mkdir()
break
except FileExistsError:
- if (timezone.now() - datetime.fromtimestamp(self.dirpath.stat().st_ctime)).days > 1:
+ if (datetime.now() - datetime.fromtimestamp(self.dirpath.stat().st_ctime)).days > 1:
# After more than one day, something was blocked, force release the lock.
self.dirpath.rmdir()
else:
diff --git a/stats/tests/tests.py b/stats/tests/tests.py
index 8ca98ef5..1b8a0130 100644
--- a/stats/tests/tests.py
+++ b/stats/tests/tests.py
@@ -69,6 +69,15 @@ class ModuleTestCase(TestCase):
CustomModuleLock.clean_locks()
self.assertFalse(lock.dirpath.exists())
+ @patch("stats.models.sleep", side_effect=RuntimeError())
+ def test_module_lock_sleep(self, mocked_sleep):
+ module = Module.objects.get(name="gnome-hello")
+ with ModuleLock(module):
+ with self.assertRaises(RuntimeError):
+ with ModuleLock(module):
+ pass
+ mocked_sleep.assert_called_once()
+
def test_modules_list(self):
response = self.client.get(reverse('modules'))
self.assertContains(response, '<li><a href="/module/zenity/">zenity</a></li>')
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]