Skip to content

Double-check for directory exists in the ensureParentDirExists(File) #978

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

Merged

Conversation

niberius
Copy link
Contributor

Hi.

I have several JUnit runners which runs cucumber tests in parallel at the same time. Each runner generate JSON file with test results to the one directory, e.g. ./target/json-files/

@CucumberOptions(
        plugin = {"json:target/json-files/Test1.json"}, ...)

Sometimes I have an issue when one of runner is unable to create reports directory because another runner already done this. And it fails with error "Failed to create directory".
I think there is a make sense to double-check if reports directory is already exists (method cucumber.runtime.io.URLOutputStream#ensureParentDirExists).

@niberius
Copy link
Contributor Author

niberius commented Apr 18, 2016

Hello.
Could you please tell me, is there any updates on this issue?
If you don't want to merge my fix, could you please advise another solution for the issue?

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running com.localhost.tests.RunTest1
Running com.localhost.tests.RunTest2
Running com.localhost.tests.RunTest3
Running com.localhost.tests.RunTest4
Tests run: 2, Failures: 0, Errors: 2, Skipped: 0, Time elapsed: 0.413 sec <<< FAILURE! - in com.localhost.tests.RunTest2
com.localhost.tests.RunTest2  Time elapsed: 0.412 sec  <<< ERROR!
cucumber.runtime.CucumberException: java.io.IOException: Failed to create directory C:\Jenkins\workspace\MyProjectWorkspace\target\json-files
    at cucumber.runtime.formatter.PluginFactory.create(PluginFactory.java:89)
    at cucumber.runtime.RuntimeOptions.getPlugins(RuntimeOptions.java:241)
    at cucumber.runtime.RuntimeOptions$1.invoke(RuntimeOptions.java:287)
    at com.sun.proxy.$Proxy15.uri(Unknown Source)
    at cucumber.runtime.junit.JUnitReporter.uri(JUnitReporter.java:160)
    at cucumber.runtime.junit.FeatureRunner.run(FeatureRunner.java:68)
    at cucumber.api.junit.Cucumber.runChild(Cucumber.java:93)
    at cucumber.api.junit.Cucumber.runChild(Cucumber.java:37)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
    at cucumber.api.junit.Cucumber.run(Cucumber.java:98)
    at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:283)
    at org.apache.maven.surefire.junit4.JUnit4Provider.executeWithRerun(JUnit4Provider.java:173)
    at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:153)
    at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:128)
    at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:203)
    at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:155)
    at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:103)
Caused by: java.io.IOException: Failed to create directory C:\Jenkins\workspace\MyProjectWorkspace\target\json-files
    at cucumber.runtime.io.URLOutputStream.ensureParentDirExists(URLOutputStream.java:53)
    at cucumber.runtime.io.URLOutputStream.<init>(URLOutputStream.java:33)
    at cucumber.runtime.io.URLOutputStream.<init>(URLOutputStream.java:24)
    at cucumber.runtime.formatter.PluginFactory.convertOrNull(PluginFactory.java:142)
    at cucumber.runtime.formatter.PluginFactory.instantiate(PluginFactory.java:99)
    at cucumber.runtime.formatter.PluginFactory.create(PluginFactory.java:87)
    at cucumber.runtime.RuntimeOptions.getPlugins(RuntimeOptions.java:241)
    at cucumber.runtime.RuntimeOptions$1.invoke(RuntimeOptions.java:287)
    at com.sun.proxy.$Proxy15.uri(Unknown Source)
    at cucumber.runtime.junit.JUnitReporter.uri(JUnitReporter.java:160)
    at cucumber.runtime.junit.FeatureRunner.run(FeatureRunner.java:68)
    at cucumber.api.junit.Cucumber.runChild(Cucumber.java:93)
    at cucumber.api.junit.Cucumber.runChild(Cucumber.java:37)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
    at cucumber.api.junit.Cucumber.run(Cucumber.java:98)
    at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:283)
    at org.apache.maven.surefire.junit4.JUnit4Provider.executeWithRerun(JUnit4Provider.java:173)
    at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:153)
    at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:128)
    at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:203)
    at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:155)
    at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:103)

@alphaCentavra
Copy link

This issue affects me too... Please apply some fix for it.

@dkowis
Copy link
Member

dkowis commented May 11, 2016

Could you provide some kind of test? Some sort of proof that this solves the problem? Parallel execution isn't officially supported yet. If you can provide tests we can add to prove that it works, we can probably get it merged.

@niberius
Copy link
Contributor Author

niberius commented May 12, 2016

I did it. Could you please review my test? If you run it without my changes in URLOutputStream, you'll get many "Failed to create parent directory" errors. But another assertion in my test which verifies that all necessary temp files and their parents are created will be passed.
I spent an hours to emulate my situation in test. Please, note that this is an intermittent issue and in my real project it reproduces ~2 times for 10 runs (in average). For temporarily fix, I've put URLOutputStream with my changes to my project with the same package name and cucumber getting my modified class from class path. Issue is not appears in that case but in my point of view, this is an unreliable solution and "bicycle". Some fixes should be made inside cucumber. Maybe my, maybe you own, as you wish...
Thank you in advance.

import org.webbitserver.HttpResponse;
import org.webbitserver.WebServer;
import org.junit.rules.TemporaryFolder;
import org.webbitserver.*;
Copy link
Contributor

Choose a reason for hiding this comment

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

No star imports please, and please undo reordering of imports. Try to reduce the PR to significant changes only.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ooops, it wasn't me, it was Intellij Idea. Sorry. Fixed in commits 6ad8186, cf811be

@RichardBradley
Copy link
Contributor

+1 -- I have had the same issue, and can confirm this fixes it.

@brasmusson brasmusson merged commit cf811be into cucumber:master Jul 31, 2016
brasmusson added a commit that referenced this pull request Jul 31, 2016
@lock
Copy link

lock bot commented Oct 25, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Oct 25, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants