From 5f5b7af77c34899bbefc2a557c5a424eccf2845f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Piotr=20Ma=C5=9Blanka?= <piotr.maslanka@henrietta.com.pl>
Date: Mon, 30 Sep 2024 11:21:05 +0200
Subject: [PATCH] fix a subtle bug in
 _CPUProfileBuilderThread.get_own_cpu_usage

---
 CHANGELOG.md                                  |  3 +++
 README.md                                     |  4 +++-
 pyproject.toml                                | 10 +++++-----
 satella/instrumentation/cpu_time/collector.py |  1 +
 tests/test_coding/test_resources.py           |  2 --
 tests/test_instrumentation/test_cpu_time.py   |  4 ++--
 6 files changed, 14 insertions(+), 10 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index dfd5322b..824ff3ea 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,9 @@
 
 * deprecated rethrow_as
 * fixed circular import
+* paths changed in pyproject.toml
+* removed prints from unit tests
+* fixed a subtle bug in _CPUProfileBuilderThread.get_own_cpu_usage
 
 # v2.25.5
 
diff --git a/README.md b/README.md
index 3c3ebab1..1f11e0f8 100644
--- a/README.md
+++ b/README.md
@@ -27,7 +27,9 @@ coverage
 ```
 
 It's still free, MIT-licensed and publicly available. No one's taking it from you :)
-I'll try to submit the builds to PyPI as well
+
+**I'll try to submit the builds to regular [PyPI](https://pypi.org/project/satella/) as well!!**
+
 
 What is Satella?
 ----------------
diff --git a/pyproject.toml b/pyproject.toml
index 5f4771da..f8eafb1b 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -45,11 +45,11 @@ max-line-length = 119
 universal = true
 
 [project.urls]
-Homepage = "https://github.com/piotrmaslanka/satella"
-Documentation = "https://satella.readthedocs.io/"
-Issues = "https://github.com/piotrmaslanka/satella/issues"
-Repository = "https://github.com/piotrmaslanka/satella"
-Changelog = "https://github.com/piotrmaslanka/satella/blob/develop/CHANGELOG.md"
+Homepage = "https://git.dms-serwis.com.pl/smokserwis/satella"
+Documentation = "https://smokserwis.docs.smok.co/satella"
+Issues = "https://git.dms-serwis.com.pl/smokserwis/satella/-/issues"
+Repository = "https://git.dms-serwis.com.pl/smokserwis/satella"
+Changelog = "https://git.dms-serwis.com.pl/smokserwis/satella/-/blob/master/CHANGELOG.md?ref_type=heads"
 
 [tool.setuptools]
 packages = ["satella",
diff --git a/satella/instrumentation/cpu_time/collector.py b/satella/instrumentation/cpu_time/collector.py
index 95d244c6..d64097ab 100644
--- a/satella/instrumentation/cpu_time/collector.py
+++ b/satella/instrumentation/cpu_time/collector.py
@@ -75,6 +75,7 @@ class _CPUProfileBuilderThread(SingleStartThread):
         time_c, times_c = self.own_load_average[-1]
         difference = time_c - time_p
         if difference == 0:
+            del self.own_load_average[-2]
             return None
         tuple_build = {}
         for field in times_v._fields:  # pylint: disable=protected-access
diff --git a/tests/test_coding/test_resources.py b/tests/test_coding/test_resources.py
index c10c67da..7f3d3896 100644
--- a/tests/test_coding/test_resources.py
+++ b/tests/test_coding/test_resources.py
@@ -44,14 +44,12 @@ class TestResources(unittest.TestCase):
 
             def acquire_connection(self):
                 v = super().acquire_connection()
-                print(f'Acquiring connection {v.id}')
                 if v.id in self.already_acquired:
                     raise RuntimeError('Reacquiring an acquired connection')
                 self.already_acquired.add(v.id)
                 return v
 
             def release_connection(self, connection) -> None:
-                print(f'Releasing connection {connection.id}')
                 self.already_acquired.remove(connection.id)
                 super().release_connection(connection)
 
diff --git a/tests/test_instrumentation/test_cpu_time.py b/tests/test_instrumentation/test_cpu_time.py
index bedf4431..a2b9c72d 100644
--- a/tests/test_instrumentation/test_cpu_time.py
+++ b/tests/test_instrumentation/test_cpu_time.py
@@ -61,9 +61,9 @@ class TestCPUTime(unittest.TestCase):
         try:
             with measure(timeout=30) as m:
                 while not m.timeouted:
-                    time.sleep(5)
+                    time.sleep(10)
                     usage = get_own_cpu_usage()
-                    if usage.user > 0.9:
+                    if usage.user > 0.6:
                         break
                 else:
                     self.fail('Timeout when waiting for significant CPU usage')
-- 
GitLab