Skip to content
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

Merged
merged 11 commits into from
Jun 19, 2018

Conversation

zougloub
Copy link
Contributor

@zougloub zougloub commented Jun 15, 2018

This PR brings:

@zougloub zougloub changed the title Misc Misc. development fixes Jun 15, 2018
@zougloub zougloub changed the title Misc. development fixes Misc. development fixes & improvements Jun 15, 2018
@zougloub zougloub force-pushed the cJ-misc branch 2 times, most recently from fc33c7c to 0a064e9 Compare June 16, 2018 21:05
Copy link
Contributor

@perone perone left a 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
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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)
Copy link
Contributor

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.

Copy link
Contributor Author

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.

elif jobs == -1:
jobs = None
else:
raise ValueError()
Copy link
Contributor

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.

Copy link
Contributor Author

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 = []
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commented code.

Copy link
Contributor Author

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
Copy link
Contributor

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO message.

Copy link
Contributor Author

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.

res = pool.apply_async(process_function, (f, param,))
results.append(res)

for idx_function, f in enumerate(list_functions):
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Member

@jcohenadad jcohenadad left a 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).

@jcohenadad
Copy link
Member

jcohenadad commented Jun 18, 2018

for comparison, i tried with different jobs on my 8-cors OSX laptop:

  • -j 1: 10 min 13 s
  • -j 2: 5 min 22 s
  • -j 4: 3 min 25 s
  • -j 6: 3 min 41 s
  • -j -1 (default=8): 3 min 10 s

nice job @zougloub 👍

)
parser.add_argument("--jobs", "-j",
type=arg_jobs,
help="# of simultaneous tests to run (jobs). -1 means # of cores",
Copy link
Member

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

Copy link
Contributor Author

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).

@random1717
Copy link
Contributor

  • Ubuntu image (2G RAM) -j -1 -> 6m 23s

@zougloub
Copy link
Contributor Author

^C should be handled now.
Note that ^Z + kill %1 can be used in such cases.

@random1717
Copy link
Contributor

@zougloub

  • Tested, total time = 5m 17s (somehow it reduced!, don't know why)
  • KeyboardInterrupt raised, but it does not terminate the process (requires ^Z) -> I'm sure it's because of multiprocessing....

@zougloub
Copy link
Contributor Author

The termination is not immediate but it should happen within a few seconds (time for Pool.terminate() to run).

@jcohenadad
Copy link
Member

i confirm keyboard interrupt works now

@zougloub zougloub merged commit 7534544 into master Jun 19, 2018
@zougloub zougloub deleted the cJ-misc branch June 19, 2018 00:35
@jcohenadad jcohenadad added the tests context: unit, integration, or functional tests label Jul 7, 2018
@jcohenadad jcohenadad added this to the v3.2.2 milestone Jul 7, 2018
@jcohenadad jcohenadad changed the title Misc. development fixes & improvements sct_testing: Implemented multiprocessing and argparse, and other improvements related to Sentry Jul 7, 2018
@jcohenadad jcohenadad changed the title sct_testing: Implemented multiprocessing and argparse, and other improvements related to Sentry Implemented multiprocessing and argparse in sct_testing, and other improvements related to Sentry Jul 7, 2018
jcohenadad pushed a commit that referenced this pull request Dec 18, 2019
Misc. development fixes & improvements

Former-commit-id: 7534544
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tests context: unit, integration, or functional tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants