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 race condition in coverage tests #423

Merged
merged 1 commit into from
Apr 11, 2018

Conversation

alamages
Copy link
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
Sponsor Collaborator

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

@@ -59,23 +58,24 @@ var _ = Describe("Coverage Specs", func() {
Eventually(session).Should(gexec.Exit(0))

// 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
Sponsor 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()) ?

Ω(err).ShouldNot(HaveOccurred())

os.RemoveAll("./_fixtures/coverage_fixture/coverage_fixture.coverprofile")
os.RemoveAll(coverFile)
Copy link
Sponsor 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
Sponsor 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.


Eventually(session).Should(gexec.Exit(0))

packages := []string{"first_package", "second_package"}

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
Sponsor 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
Sponsor Collaborator

Bump @alamages any thoughts on the review?

@@ -89,3 +89,8 @@ func startGinkgo(dir string, args ...string) *gexec.Session {
Ω(err).ShouldNot(HaveOccurred())
return session
}

func removeSuccessfully(path string) {
Copy link
Sponsor 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
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
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
Copy link
Collaborator Author

alamages commented Apr 6, 2018

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

@williammartin
Copy link
Sponsor Collaborator

@alamages gogogo

@alamages
Copy link
Collaborator Author

alamages commented Apr 9, 2018

@williammartin done :D

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

Decided to use removeSuccessfully

@williammartin
Copy link
Sponsor 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
Copy link
Collaborator Author

@williammartin it should be ok now

@williammartin
Copy link
Sponsor 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.

None yet

2 participants