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

Fix @BeforeSuite usages to prevent excessive code execution #3551

Merged
merged 1 commit into from
Sep 8, 2017

Conversation

cmnbroad
Copy link
Collaborator

@cmnbroad cmnbroad commented Sep 6, 2017

There is quite a bit of code annotated with @BeforeSuite that should probably just be @BeforeClass. @BeforeSuite code can run even when no methods in the class are selected in the current suite. Most of it is harmless, but some of it is painfully slow, i.e., using gradle to run a single test method always causes the BwaMemIntegrationTest code to create an index image for the large test reference, which takes 1-2 minutes, before the selected test even starts.

We should probably reserve @BeforeSuite for test-infrastructure setup code; most test classes should use @BeforeClass instead.

@@ -16,7 +16,7 @@


public final class QualQuantizerUnitTest extends BaseTest {
@BeforeSuite
@BeforeClass
public void before() {
Copy link
Member

Choose a reason for hiding this comment

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

is this an empty method?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hm, yeah, that should probably just come out. Even better.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

final ImmutablePair<List<String>, ReadCountCollection> randomData = generateRandomReadCountCollection(
@BeforeClass
public void before() {
HOMO_SAPIENS_GERMLINE_CONTIG_PLOIDY_ANNOTATIONS = ContigGermlinePloidyAnnotationTableReader
Copy link
Member

Choose a reason for hiding this comment

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

This seems worse, why change these?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I did this because the static blocks always execute (AFAICT), even if you run a single test from another package, and it calls code that emits log output:

13:15:52.512 INFO ContigGermlinePloidyAnnotationTableReader - Ploidy tags: SEX_XX, SEX_XY

which looks misplaced depending on the context. But that is a separate problem - my main goal with this PR was to eliminate the BWA indexing, since thats super slow and it happens every time. I'm happy to revert the changes in this file for now.

@@ -14,7 +14,7 @@

GenotypeLikelihoodCalculators calcs;

@BeforeSuite
@BeforeClass
public void init(){
Copy link
Member

Choose a reason for hiding this comment

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

I feel like most of these before suite should just be initialized inline where they're declared. Or replaced with a getter that returns a new instance of the thing on demand. That's a bigger change though.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Agreed. I was trying to minimize the changes, but wanted to get rid of unnecessary @BeforeSuites.


public class BwaMemIntegrationTest extends BaseTest {

private BwaMemIndex index;

@BeforeSuite
@BeforeClass
public void loadIndex() {
Copy link
Member

Choose a reason for hiding this comment

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

Does this really take minutes? that's gross... we should try to change it uses a smaller test file if that wouldn't reduce the power of the test unreasonably.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It seems to take about 2 minutes on my laptop.

Copy link
Contributor

Choose a reason for hiding this comment

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

I am suspecting this is leading to the new indexing step I see when running tests locally, and does increase the test time by ~3min.

Copy link
Member

@lbergelson lbergelson left a comment

Choose a reason for hiding this comment

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

@cmnbroad A few minor comments. 👍 to merge whatever you decide to do with those. The before and after blocks for the most part seem like a bad idea to me in general, they tend to be very fragile. Getting rid of them is a bigger change though than just limiting the scope the run in though.

@codecov-io
Copy link

codecov-io commented Sep 6, 2017

Codecov Report

Merging #3551 into master will increase coverage by 0.011%.
The diff coverage is n/a.

@@               Coverage Diff               @@
##              master     #3551       +/-   ##
===============================================
+ Coverage     79.928%   79.938%   +0.011%     
- Complexity     17900     17901        +1     
===============================================
  Files           1199      1199               
  Lines          65015     65015               
  Branches       10124     10124               
===============================================
+ Hits           51965     51972        +7     
+ Misses          9016      9011        -5     
+ Partials        4034      4032        -2
Impacted Files Coverage Δ Complexity Δ
...er/tools/spark/sv/discovery/AlignmentInterval.java 88.889% <0%> (+0.463%) 52% <0%> (+1%) ⬆️
...oadinstitute/hellbender/utils/gcs/BucketUtils.java 79.87% <0%> (+3.896%) 39% <0%> (ø) ⬇️

@cmnbroad cmnbroad force-pushed the cn_fix_test_suite_isolation branch from c11f081 to 3868349 Compare September 7, 2017 17:40
@cmnbroad cmnbroad changed the title Fix static test blocks and @BeforeSuite usages to prevent excessive code execution Fix @BeforeSuite usages to prevent excessive code execution Sep 7, 2017
…ode execution when tests aren't included in a suite.
@cmnbroad cmnbroad force-pushed the cn_fix_test_suite_isolation branch from 3868349 to 788b48d Compare September 8, 2017 14:58
@cmnbroad cmnbroad merged commit 51f035a into master Sep 8, 2017
@cmnbroad cmnbroad deleted the cn_fix_test_suite_isolation branch September 8, 2017 18:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants