You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by bu...@apache.org on 2004/03/03 23:02:32 UTC

DO NOT REPLY [Bug 27420] New: - cleanup() never called on ant class loader when running junit

DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=27420>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=27420

cleanup() never called on ant class loader when running junit

           Summary: cleanup() never called on ant class loader when running
                    junit
           Product: Ant
           Version: 1.7Alpha (nightly)
          Platform: PC
        OS/Version: Windows XP
            Status: NEW
          Severity: Normal
          Priority: Other
         Component: Optional Tasks
        AssignedTo: dev@ant.apache.org
        ReportedBy: drabe@opentext.com


When I run my unit tests with fork="false", the JVM heap size continually 
increases. I've duplicated this with a simple test case. In short, I believe 
there's a bug in the ant junit task because it doesn't clean up its 
classloaders.

Here's the scenario: I have five identical testcases (each a subclass of an 
abstract test case). The abstract class declares a "static Integer memoryHog[] 
= new Integer[ 500000 ];". When each class is loaded, then, it should allocate 
a couple megabytes of memory. The test method itself sleeps for five seconds 
(to make it easier to watch what's going on), and then prints out totalMemory().

When I run this from ant, I get the following output:
test:
    [junit] Running MyTest
    [junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 5 sec

    [junit] Running MyTest1
    [junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 5 sec
    [junit] Output:
    [junit] Max memory: 6828

    [junit] Running MyTest2
    [junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 5 sec
    [junit] Output:
    [junit] Max memory: 8144

    [junit] Running MyTest3
    [junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 5 sec
    [junit] Output:
    [junit] Max memory: 11640

    [junit] Running MyTest4
    [junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 5.001 sec
    [junit] Output:
    [junit] Max memory: 15168

    [junit] Running MyTest5
    [junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 5 sec
    [junit] Output:
    [junit] Max memory: 18636

The debug output confirms what I see in task manager -- heap size increasing by 
2-3Mb for each testcase.

Next, I changed JUnitTask to call cleanup() on the class loader after running 
the tests. This is the diff (against CVS HEAD):
RCS 
file: /home/cvspublic/ant/src/main/org/apache/tools/ant/taskdefs/optional/junit/
JUnitTask.java,v
retrieving revision 1.93
diff -r1.93 JUnitTask.java
974a975
> 				classLoader.cleanup();

Now when I run the tests, I don't see the increasing memory problem:
test:
    [junit] Running MyTest
    [junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 5 sec

    [junit] Running MyTest1
    [junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 5 sec
    [junit] Output:
    [junit] Max memory: 6828

    [junit] Running MyTest2
    [junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 5 sec
    [junit] Output:
    [junit] Max memory: 6828

    [junit] Running MyTest3
    [junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 5 sec
    [junit] Output:
    [junit] Max memory: 6828

    [junit] Running MyTest4
    [junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 5 sec
    [junit] Output:
    [junit] Max memory: 6828

    [junit] Running MyTest5
    [junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 5 sec
    [junit] Output:
    [junit] Max memory: 6828

However, I don't profess to know enough about classloaders OR ant OR junit to 
know if this is the right fix. In fact, the ant unit tests fail with my mod, so 
it's probably not right. (DefaultExcludesTest:test1 fails.)

Regards,

Daniel Rabe
Sr. Software Architect
Open Text, Inc.
Boulder, Colorado
http://www.opentext.com

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org