-
Notifications
You must be signed in to change notification settings - Fork 1k
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
DataProvider: possibility to unload dataprovider class, when done with it #2739
DataProvider: possibility to unload dataprovider class, when done with it #2739
Conversation
@dsankouski - There are failures because the code style was not applied Please Run |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dsankouski - I still have the basic doubt around the following in this PR:
- When I provide a string version of my class as my data provider class, does it mean that the class exists in my class path but I am just not loading it before hand and will trigger the loading only when I run the data driven test which uses this class?
testng-core/src/main/java/org/testng/internal/DataProviderLoader.java
Outdated
Show resolved
Hide resolved
testng-core/src/main/java/org/testng/internal/DataProviderMethodRemovable.java
Show resolved
Hide resolved
testng-core/src/main/java/org/testng/internal/annotations/JDK15AnnotationFinder.java
Show resolved
Hide resolved
testng-core/src/main/java/org/testng/internal/DataProviderLoader.java
Outdated
Show resolved
Hide resolved
&& !dp.getDataProviderDynamicClass().isEmpty(); | ||
if (isDynamicDataProvider) { | ||
try { | ||
dataProviderClass = new DataProviderLoader() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are creating on the fly instances of DataProviderLoader()
to load the class that was specified as a string attribute in the @Test
annotation. This means that this object of DataProviderLoader()
immediately becomes eligible for a GC. So if the loader object gets GC'ed then all the classes that it caused to load would be unloaded as well.
So what is going to be the expected behaviour when the DataProviderLoader
object got GC'ed even before a data provider was actually invoked? Wouldn't that cause ClassNotFoundException
or NoClassDefFoundError
for the test case which is using a dynamic data provider ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Class holds a reference to it's classloader. So, in order to garbage collect a classloader, all class instances should be collected first.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are clearing only the instance. So does it mean that when all instances associated with a class are GC'ed the corresponding class also would get GC'ed from the perm space and thus cause the ClassLoader also to do the same ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's right.
98475c7
to
a0b7229
Compare
56f0713
to
2112e44
Compare
@dsankouski - My bad for getting back late on this. Can you please help fix the merge conflicts and update this PR branch? Lets work on getting this merged asap. |
2112e44
to
8bdc42b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new tests are failling on j9 jvm. They should be fixed or skipped when j9 is used.
Can we please have this fixed ? https://github.com/cbeust/testng/runs/6096462677?check_suite_focus=true
|
…h it With current Data providers implementation, it's code will stick around in method area (JVM spec $2.5.4) for the entire test run. By specifying dataprovider class with it's full qualified name, and by using new custom classloader to load it, when needed, JVM gets a chance to unload dataprovider class, when we're done with it. Testing dataprovider class unload is performed by analysing memory dumps. Also, there is a test(comparePerformanceAgainstCsvFiles) to measure performance of data as code approach against common data approch, where data is stored in csv files.
8bdc42b
to
c1c74b6
Compare
@krmahadevan @juherr, throw SkipException, in |
With current Data providers implementation, it's code will stick around
in method area (JVM spec $2.5.4) for entire test run.
By specifying dataprovider class with it's full qualified name, and
by using new custom classloader to load it, when needed, JVM gets a
chance to unload dataprovider class, when we're done and deleted
all links to it
Fixes #2724 .
Did you remember to?
CHANGES.txt
./gradlew autostyleApply