GitHub user silencerby opened a pull request:

    https://github.com/apache/maven-surefire/pull/42

    Testcase: 'java.io.IOException: Stream Closed' if test's console output 
exceeds 1Mb

    A test case to reproduce 'java.io.IOException: Stream Closed'. Which is 
thrown when FailSafe runs a couple of integration tests with a custom Junit 
test runner and their console output exceeds 1Mb.
    
    My comments below might help to pinpoint the cause of the problem.
    
    Applicable only for JUnitCoreRunListener (forced in the provided test case 
by specifying groups in failsafe's configuration). And only if Test's and/or 
TestRunner's console output exceeds 1Mb.
    
    If console output exceeds 1Mb limit set on 
Utf8RecodingDeferredFileOutputStream.deferredFileOutputStream field, the 
DeferredFileOutputStream will switch from 
DeferredFileOutputStream.memoryOutputStream to a stream backed by 
DeferredFileOutputStream.outputFile.
    
    When TestSetRunListener.testSetCompleted event is received, 
TestSetRunListener will call Utf8RecodingDeferredFileOutputStream.free method 
that in turn will delete 
Utf8RecodingDeferredFileOutputStream.deferredFileOutputStream.getFile() file. 
And for a 'double tap' the same free() method will be called in 
TestSetStats.reset()
    
            wrap.getStdout().free();
            wrap.getStdErr().free();
    
            globalStatistics.add( detailsForThis );
            detailsForThis.reset();
    
    But having TestSetRunListener.testSetCompleted event received is not a 
guarantee that Fork is finished. And an output of the next TestSet in the same 
Fork will be pushed into the already closed stream (backed by 
DeferredFileOutputStream.outputFile).
    
    Hence, 'java.io.IOException: Stream Closed' exception.
    
    I'm not familiar enough with the surefire's codebase to assert the impact 
of any fixes I might suggest.
    But I think the whole usage of 
Utf8RecodingDeferredFileOutputStream/DeferredFileOutputStream in 
TestSetRunListener must be relooked at. I mean, underlying file of 
DeferredFileOutputStream is meticulously deleted on 'testSetCompleted' event 
but blissfully discarded in TestSetRunListener.clearCapture() method on 
testSucceeded, testError, testFailed and testSkipped events.


You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/silencerby/maven-surefire master

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/maven-surefire/pull/42.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #42
    
----
commit 863f0011c782e5089f77f0b31dbba22cb71c0412
Author: Vitali Skleenkov <[email protected]>
Date:   2014-07-23T08:30:22Z

    Testcase: 'java.io.IOException: Stream Closed' if test's console output
    exceeds 1Mb

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to