-
-
Notifications
You must be signed in to change notification settings - Fork 101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implemented multiprocessing and argparse in sct_testing, and other improvements related to Sentry #1872
Conversation
fc33c7c
to
0a064e9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added some comments, I'm marking this PR with approve because I know these changes can take some time and they might be another different PR.
- bash -c 'echo -ne "[run]\nconcurrency = multiprocessing\nparallel = True\n" > .coveragerc' | ||
- COVERAGE_PROCESS_START="$PWD/.coveragerc" COVERAGE_FILE="$PWD/.coverage" PYTHONPATH="$PWD" sct_testing -d 1 | ||
- coverage combine | ||
- ./unit_testing.sh |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we shouldn't separate these two different tests. Because otherwise, we'll never know what lacks unit-testing or integration tests. However, I'm not sure if coveralls accepts two kinds of distinct testing report.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMHO:
- We'll know that we lack coverage, and improving it can be achieved either by unit or integration tests...
- Coveralls is nice and sexy but not as flexible as the bare
coverage
; we can also get coverage reports locally.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mentioned having separate coverages because the integration tests are very different than the unit tests. In integration tests, we test with real data, while on unit testing we test with mocked data. But as you mentioned, we can have separate reports locally, so that's not an issue.
@@ -214,4 +215,6 @@ def download_data(urls, verbose): | |||
|
|||
if __name__ == "__main__": | |||
sct.init_sct() | |||
main() | |||
res = main() | |||
raise SystemExit(res) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will change the exception KeyboardInterrupt
for a SystemExit
, it might confuse error reporting, exception handling, etc. Please see the #1658. Let's say someone uses sct_download_data
later (as an API), it will silence the KeyboardInterrupt
exception in favor of a C-style error reporting of returning a code.
If there is any other way of doing that it would be nice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The main()
function was not exactly behaving as an API-callable function (should have one named download_data()
or similar) but rather like a main()
function...
As the user could ^C anytime, I just removed the try/catch and the user will get a standard traceback message, as in every other SCT script.
scripts/sct_testing.py
Outdated
elif jobs == -1: | ||
jobs = None | ||
else: | ||
raise ValueError() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing error message in the ValueError
exception.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't matter as the message doesn't get brought to the user's attention (argparse is eating it).
module_testing = importlib.import_module('test_' + fname) | ||
# initialize default parameters of function to test | ||
param.args = [] | ||
# param.list_fname_gt = [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Commented code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't add any commented code, it was just moved from another location.
param_test.default_args = param.args | ||
param_test.args = param.args[i] | ||
param_test.test_integrity = True | ||
# if list_fname_gt is not empty, assign it |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Commented code.
param_test = test_function(param_test) | ||
except Exception as e: | ||
list_status_function.append(1) | ||
list_output.append("TODO exception: %s" % e) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO message.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was here before... but yeah, one day.
scripts/sct_testing.py
Outdated
res = pool.apply_async(process_function, (f, param,)) | ||
results.append(res) | ||
|
||
for idx_function, f in enumerate(list_functions): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My only concern here is if a message is printed from inside the testing, that will appear here out-of-order, causing confusion on which testing the error message came from because it is executing all of them in parallel.
One solution to that would be capturing and returning the stdout
and stderrr
inside the process_function()
, so you can print these messages here later in order.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure what you mean, the messages are indeed collected and (in case of error) printed in order.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I understood, it is capturing only exceptions but not any other message such as prints, logging, etc. That's my concern.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- i tried launching
sct_testing
and then did a ctrl+c to quit, but it kept running (after 50 ctrl+c i eventually closed my terminal).
for comparison, i tried with different jobs on my 8-cors OSX laptop:
nice job @zougloub 👍 |
scripts/sct_testing.py
Outdated
) | ||
parser.add_argument("--jobs", "-j", | ||
type=arg_jobs, | ||
help="# of simultaneous tests to run (jobs). -1 means # of cores", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i would replace with [...] -1 means # of available cores
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed (plus, it's not -1 but 0 now... I can't remember in what state of mind i was when I decided to use -1 instead of zero).
|
^C should be handled now. |
|
The termination is not immediate but it should happen within a few seconds (time for |
i confirm keyboard interrupt works now |
Misc. development fixes & improvements Former-commit-id: 7534544
This PR brings:
sct_testing
usage of multiprocessing (Performance improvements for the tests #1539)-j 1
is called)sct_testing
usage of argparse (no problem since it's a script used for development only)sct_download_data
to not send Sentry messages (No need to call Sentry if user quits with CTRL+C #1844)sct_testing