Skip to content

Commit

Permalink
fix[test]: improve context switch test
Browse files Browse the repository at this point in the history
The test was relying on a context switch to happen given a number of iterations of a specific code.
The test began to fail on python 3.12 on macOS.
Use time.sleep to force a context switch.

Signed-off-by: mayeut <[email protected]>
  • Loading branch information
mayeut committed Jul 30, 2023
1 parent 52276b7 commit ac577a6
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions psutil/tests/test_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -1059,12 +1059,12 @@ def test_num_fds(self):
def test_num_ctx_switches(self):
p = psutil.Process()
before = sum(p.num_ctx_switches())
for _ in range(500000):
for _ in range(2):
time.sleep(0.05) # this shall ensure a context switch happens
after = sum(p.num_ctx_switches())
if after > before:
return
raise self.fail(
"num ctx switches still the same after 50.000 iterations")
raise self.fail("num ctx switches still the same after 2 iterations")

def test_ppid(self):
p = psutil.Process()
Expand Down

0 comments on commit ac577a6

Please sign in to comment.