-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix - #56: Force CPU frequency to 0 when unable to fetch it. On some system, it appears to not be feasible to fetch the frequency. Under such circumstances, the CPU frequency is set to 0 and a warning is emited.
- Loading branch information
Showing
4 changed files
with
53 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import mock | ||
import pathlib | ||
import sqlite3 | ||
|
||
|
||
@mock.patch('pytest_monitor.sys_utils.psutil.cpu_freq', return_value=None) | ||
def test_when_cpu_freq_cannot_fetch_frequency(cpu_freq_mock, testdir): | ||
"""Make sure that pytest-monitor does the job when we have issue in collecing context resources""" | ||
# create a temporary pytest test module | ||
testdir.makepyfile(""" | ||
import time | ||
def test_ok(): | ||
time.sleep(0.5) | ||
x = ['a' * i for i in range(100)] | ||
assert len(x) == 100 | ||
""") | ||
|
||
# run pytest with the following cmd args | ||
result = testdir.runpytest('-vv') | ||
|
||
# fnmatch_lines does an assertion internally | ||
result.stdout.fnmatch_lines(['*::test_ok PASSED*']) | ||
|
||
pymon_path = pathlib.Path(str(testdir)) / '.pymon' | ||
assert pymon_path.exists() | ||
|
||
# make sure that that we get a '0' exit code for the test suite | ||
result.assert_outcomes(passed=1) | ||
|
||
db = sqlite3.connect(str(pymon_path)) | ||
cursor = db.cursor() | ||
cursor.execute('SELECT ITEM FROM TEST_METRICS;') | ||
assert 1 == len(cursor.fetchall()) # current test | ||
cursor = db.cursor() | ||
cursor.execute('SELECT CPU_FREQUENCY_MHZ FROM EXECUTION_CONTEXTS;') | ||
rows = cursor.fetchall() | ||
assert 1 == len(rows) | ||
assert rows[0][0] == 0 | ||
|