Skip to content

Fix race condition in coverage tests#423

Merged
williammartin merged 1 commit into
onsi:masterfrom
alamages:coverage-tests-fix
Apr 11, 2018
Merged

Fix race condition in coverage tests#423
williammartin merged 1 commit into
onsi:masterfrom
alamages:coverage-tests-fix

Conversation

@alamages

Copy link
Copy Markdown
Collaborator

Tests now generate coverprofile files into different paths so now they don't
interfere with other and can be run successfully in parallel. Also since
the files now have different names, some extra cleanup was required.

Related issue: #394

@williammartin

Copy link
Copy Markdown
Collaborator

Thanks for looking at this, will try to review today.

Comment thread integration/coverage_test.go Outdated
// Check that the correct file was created
_, err := os.Stat("./_fixtures/coverage_fixture/coverage.txt")
coverFile := "./_fixtures/coverage_fixture/coverage.txt"
_, err := os.Stat(coverFile)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can we use: Expect(coverFile).To(BeARegularFile()) ?

Comment thread integration/coverage_test.go Outdated
Ω(err).ShouldNot(HaveOccurred())

os.RemoveAll("./_fixtures/coverage_fixture/coverage_fixture.coverprofile")
os.RemoveAll(coverFile)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

WDYT about wrapping these in Expect(os.RemoveAll(coverFile)).To(Succeed()).

I'm torn on this style, on the one hand it's an assertion that isn't really related to the behaviour under test, on the other hand, I've been bitten so many times by debris from previous tests.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

If coverFile is a regular file, can we use os.Remove(coverFile). Seeing RemoveAll in code leads me to believe we are deleting a directory.

Comment thread integration/coverage_test.go Outdated

for _, p := range packages {
coverFile := fmt.Sprintf("./_fixtures/combined_coverage_fixture/%s/coverage.txt", p)
coverFile := fmt.Sprintf("./_fixtures/combined_coverage_fixture/%s/coverage1.txt", p)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I wonder whether we can come up with more self-explaining names for these files than 1,2,3 etc. e.g. coverage-recursive.txt

I'm also not super clear on why these all have different names rather than different output dirs but I'm definitely missing something.

@williammartin

Copy link
Copy Markdown
Collaborator

Bump @alamages any thoughts on the review?

return session
}

func removeSuccessfully(path string) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can we just use Expect(os.RemoveAll(path)).To(Succeed()) ? Do we need this extra indirection to another method as well, or is it cause you don't want the assertion in the test block itself?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yes, the initial idea was not to have the assertion within the block itself. The PR is still WIP since we started refactoring to make sure all generated coverage files are always removed.

@alamages

Copy link
Copy Markdown
Collaborator Author

@williammartin you can take a look at this PR again now

We specify different output coverage files instead of different output directories because:

  • coverage filenames where already being provided in the tests, we just had to change their names so they won't conflict
  • specifying different output directory for coverage in recursive mode would only affect the combined coverage file. The intermediates package coverage files would still be generated in the default path.

Let me know if you want any further changes on this, thanks!

@alamages

alamages commented Apr 6, 2018

Copy link
Copy Markdown
Collaborator Author

Once this PR: #446 is merged I will have to merge with master and adapt the changes.

@williammartin

Copy link
Copy Markdown
Collaborator

@alamages gogogo

@alamages

alamages commented Apr 9, 2018

Copy link
Copy Markdown
Collaborator Author

@williammartin done :D

@alamages alamages dismissed williammartin’s stale review April 9, 2018 16:47

Decided to use removeSuccessfully

@williammartin

Copy link
Copy Markdown
Collaborator

Can you fix up the commits as well please? I'd rather not have a git tree containing a bunch of wip commits.

@alamages alamages force-pushed the coverage-tests-fix branch 3 times, most recently from e1f0152 to 3f8c435 Compare April 11, 2018 16:44
Tests now generate coverprofile files into different paths so now they don't
interfere with each other and can be run successfully in parallel.

Some extra changes:
- Use BeARegularFile() to check for file existance in coverage_test
- Wrap every It with a Context to properly remove any generated file
- Use removeSuccessfully helper function to cleanup generated files
@alamages alamages force-pushed the coverage-tests-fix branch from 3f8c435 to a5a8ff7 Compare April 11, 2018 16:45
@alamages

Copy link
Copy Markdown
Collaborator Author

@williammartin it should be ok now

@williammartin

Copy link
Copy Markdown
Collaborator

LGTM thanks

@williammartin williammartin merged commit ab9c08b into onsi:master Apr 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants