Skip to content

Commit 1bdc99f

Browse files
committed
tests: Add io priority tests
1 parent 1163c76 commit 1bdc99f

File tree

1 file changed

+30
-4
lines changed

1 file changed

+30
-4
lines changed

tests/test_command_runner.py

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
__author__ = 'Orsiris de Jong'
1919
__copyright__ = 'Copyright (C) 2015-2025 Orsiris de Jong'
2020
__licence__ = 'BSD 3 Clause'
21-
__build__ = '2023122801'
21+
__build__ = '2025040901'
2222

2323

2424
import sys
@@ -679,17 +679,43 @@ def on_exit():
679679
assert ON_EXIT_CALLED is True, 'On exit was never called'
680680

681681

682-
def test_priority():
683-
def check_nice(process):
682+
def test_low_priority():
683+
def check_low_priority(process):
684684
niceness = os.nice(process.pid)
685+
io_niceness = psutil.Process(process.pid).ionice()
685686
if os.name == 'nt':
686687
assert niceness == 16384, 'Process niceness not properly set: {}'.format(niceness)
688+
assert io_niceness == 1, 'Process io niceness not set properly: {}'.format(io_niceness)
687689
else:
688690
assert niceness == 15, 'Process niceness not properly set: {}'.format(niceness)
691+
assert io_niceness == 3, 'Process io niceness not set properly: {}'.format(io_niceness)
689692
print('Nice !')
690693

691694
def command_runner_thread():
692-
return command_runner_threaded(PING_CMD, priority='low', io_priority='low', process_callback=check_nice)
695+
return command_runner_threaded(PING_CMD, priority='low', io_priority='low', process_callback=check_low_priority)
696+
697+
698+
thread = threading.Thread(
699+
target=command_runner_thread, args=()
700+
)
701+
thread.daemon = True # thread dies with the program
702+
thread.start()
703+
704+
705+
def test_high_priority():
706+
def check_high_priority(process):
707+
niceness = os.nice(process.pid)
708+
io_niceness = psutil.Process(process.pid).ionice()
709+
if os.name == 'nt':
710+
assert niceness == 128, 'Process niceness not properly set: {}'.format(niceness)
711+
assert io_niceness == 3, 'Process io niceness not set properly: {}'.format(io_niceness)
712+
else:
713+
assert niceness == -15, 'Process niceness not properly set: {}'.format(niceness)
714+
assert io_niceness == 1, 'Process io niceness not set properly: {}'.format(io_niceness)
715+
print('Nice !')
716+
717+
def command_runner_thread():
718+
return command_runner_threaded(PING_CMD, priority='low', io_priority='low', process_callback=check_high_priority)
693719

694720

695721
thread = threading.Thread(

0 commit comments

Comments
 (0)