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

Streamline native injection w.r.t cloning #1996

Closed
wants to merge 1 commit into from

Conversation

krmahadevan
Copy link
Member

Closes #1994

Currently as part of supporting native injection
TestNG resorts to invoking the “clone()” method
on the parameter being natively injected.

This becomes a problem because XmlTest is the only
internal TestNG object that implements the Cloneable
interface wherein it resorts to something like a deep
copy and adds the cloned instance to the XmlSuite.

This causes a lot of phony XmlTest objects to be
added up to the suite and causes issues as detailed
in the bug.

Fixed this by introducing a marker interface to
indicate to TestNG to skip cloning and use the object
as is. Annotated “XmlTest” with this annotation
so that we dont clone xmltest but instead use it
as is.

Yes this will expose the XmlTest object, but its
already exposed to the end user via various different
means. So I guess we are ok here.

Fixes #1994 .

Did you remember to?

  • Add test case(s)
  • Update CHANGES.txt

Closes testng-team#1994

Currently as part of supporting native injection
TestNG resorts to invoking the “clone()” method 
on the parameter being natively injected.

This becomes a problem because XmlTest is the only
internal TestNG object that implements the Cloneable
interface wherein it resorts to something like a deep
copy and adds the cloned instance to the XmlSuite.

This causes a lot of phony XmlTest objects to be 
added up to the suite and causes issues as detailed
in the bug.

Fixed this by introducing a marker interface to 
indicate to TestNG to skip cloning and use the object
as is. Annotated “XmlTest” with this annotation 
so that we dont clone xmltest but instead use it 
as is.

Yes this will expose the XmlTest object, but its 
already exposed to the end user via various different
means. So I guess we are ok here.
@krmahadevan krmahadevan requested a review from juherr January 1, 2019 14:37
Copy link
Member

@juherr juherr left a comment

Choose a reason for hiding this comment

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

In fact, the issue is located in the clone method of XmlTest where we have a side effect.
In fact, all XmlXxx classes should not be cloned (we don't have injection tests for them).
But, IMO, the best way to fix the issue is to remove the clone method which has no real value add here.

@krmahadevan
Copy link
Member Author

But, IMO, the best way to fix the issue is to remove the clone method which has no real value add here.

No we can't do that. XmlTest is exposed to users and I dont know how many people are relying on the customized clone() method that XmlTest provides. So I feel that we cannot just like that remove off the behavior.

@krmahadevan
Copy link
Member Author

@juherr - Please let me know if you are fine with my responses and if we can merge this.

@juherr
Copy link
Member

juherr commented Jan 1, 2019

Ok for not removing the clone method but I'd prefer that the bug is fixed instead of overengineering.

https://github.com/cbeust/testng/blob/master/src/main/java/org/testng/xml/XmlTest.java#L488

-XmlTest result = new XmlTest(getSuite()); 
+XmlTest result = new XmlTest(getSuite().clone());

Should fix the issue too.

Please, deprecate the clone methods too.

@krmahadevan
Copy link
Member Author

@juherr

+XmlTest result = new XmlTest(getSuite().clone());

This will break backward compatibility in terms of what we are providing as a functionality via the clone() method to all existing users. The current functionality guarantees that when I clone an XmlTest object, it would automatically also get added to the current XmlSuite. With the change you are suggesting, that will be broken.

@krmahadevan
Copy link
Member Author

instead of overengineering.

Where did you feel that the fix was over-engineering? Can you please help call that out? Just curious.

@krmahadevan
Copy link
Member Author

Ping @juherr

@juherr
Copy link
Member

juherr commented Jan 3, 2019

Where did you feel that the fix was over-engineering?

Using annotations instead of just fixing the issue.

This will break backward compatibility in terms of what we are providing as a functionality via the clone() method to all existing users. The current functionality guarantees that when I clone an XmlTest object, it would automatically also get added to the current XmlSuite. With the change you are suggesting, that will be broken.

Rigth but I can't imagine someone is using clone() method and the implementation doesn't respect the contract.
BTW, I think making this breaking change in the major version has low risks.

@krmahadevan
Copy link
Member Author

@juherr

Using annotations instead of just fixing the issue.

I felt that was a bit harsh. I was also fixing the issue. Just that I fixed it in a different way and it perhaps didn't align to what you were expecting.

Anyways. I am closing this PR.

@krmahadevan krmahadevan closed this Jan 4, 2019
@juherr
Copy link
Member

juherr commented Jan 4, 2019

Right, it fixed the issue too but thanks to a workaround. I hope I didn't offend you.

I still think we should remove the Clonable here, and that's why I prefer to wait before releasing because it allows us some regressions.

@krmahadevan
Copy link
Member Author

krmahadevan commented Jan 4, 2019 via email

@juherr
Copy link
Member

juherr commented Jan 4, 2019

100% agree with you.

But the responsibility is not the same when you use a beta version.
To be honest, I really don't care to have regressions between beta versions.
And a major version is an opportunity to have API changes (which is not the case with minor versions).
I agree too with the deprecation strategy but I'd like to move quicker at the same time. I think ome compromises are possible if we feel I won't break too many things (that's my opinion with clone here).

If you think it is too risky, so we can merge this PR but with comments for the temporary code and without making it public.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants