-
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
Segregate native & user listeners before ordering #2864
Conversation
befbb43
to
9930fa5
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.
I don't get the link between the issue and the need to have an order in listeners. Could you explain?
testng-core/src/test/java/test/listeners/issue2771/TestCaseSample.java
Outdated
Show resolved
Hide resolved
Test specific listener is altering the state of a test. Now we are ensuring that we maintain insertion order but that is specific only to test listeners and not applicable to native listeners. |
9930fa5
to
755cfd4
Compare
Ok that's clear. Why not having only the mandatory listeners in the list? In mean exclude the reporters at least. Otherwhise, why not introducing an annotation with a priority value and allow users to plug their listener in the level they want? |
I just kept the intent simple of segregating all native listeners (which includes listeners as well).
Because it can still be interfered by a user, by defining the same priority for their listeners. My intent was to just have them separated and ensure that the TestNG listeners always honour what a user's listener may have done in terms of changing the state of one or more tests. |
ping @juherr - Can you please let me know if I can go ahead with merging this PR ? |
ping @juherr |
Sorry but I still don't understand the issue or the fix. |
@juherr - Please let me know if that answers the question. |
I don't understand everything but what I propose is:
WDYT? |
The current implementation is doing all of this already except that, instead of taking in a package, I am dealing with hard coded listener names. I resorted to this because I didn't want any user created listener under the package For the documentation part, I have added javadocs at the |
But doing it under
I still think reporters should be excluded from the list because they are not supposed to be involved in the test lifecycle or change states.
The current javadoc explains the what but not the why. It is dedicated not to users but to devs who will update the base code later. Just explain why internal listeners must be in a specific order. |
755cfd4
to
a164c2d
Compare
Yes and I didn't find any other way in which I can accommodate user behaviour within an IDE. I first thought I would hard code this, but then realised that if the IntelliJ listener changed its package, then this behaviour would be broken. If needed, I can have this removed, but this would be a sub-standard user experience. I am open to any suggestions that can streamline this.
The api does not restrict this and so I accommodated the reporting listeners as well.
Added this documentation and pushed the change.
Yes, that's a valid point. But right now they are too intertwined and I can de-couple them in a separate PR (and am glad that via this PR, this discrepancy came out) |
Could you have a try in another branch? I think it should be quick to inject 2 object instances and call them when needed. |
@juherr I thought I could also do that, but it looks like ConfigurationListener gets injected into the TestRunner's config listeners set and that gets exposed to callers outside of TestRunner. So I don't know where all this is going to impact and hence I felt it would be easy for me to just deal with that as a separate PR. |
@krmahadevan Please check https://github.com/juherr/testng/tree/bugfix/github-2864 where I made the expected refactoring. It should fix the issue. Could you check and confirm? The feature you add here is great and just needs to be polished before the merge. |
@juherr - Thanks for taking the time to create this changeset. It looks good. I ran the tests locally as well and all is well. Can you please have this changeset raised as a PR and lets merge it. I will rebase off of master after the merge and then build upon that |
a164c2d
to
37cd664
Compare
@juherr - I think now this PR is in a shape to be merged. I have built upon your changes and did the same thing of removing out |
Once No more problems with IntelliJ listeners? |
Because it also implements ITestListener which is needed by TestRunner and I don't want to keep passing around stuff.
That would still be there because we are now not ordering anything at all. Do you want that to be considered ? If yes, then I would need to bring back the Listener Order determining logic. |
But you should because it is part of the internal logic.
It is ordered by insertion order, right? IntelliJ is supposed to add its own listener at the beginning and everything should work. I'd like a confirmation if I'm right. |
This is going to be a much more invasive changeset against the original one. I will make the change.
yes we work on insertion order, but if the user's listener got wired in after intellij's UI listener, then it wont know of the changes that the user's listener made to the test state and so, it displays a test as passed even though the user's listener explicitly marked it as failed.
Yes. It looks like a stripped down version of the listener orderer is required to get this done. I will update this PR with those changes. |
@juherr - Basic question. How is this round about way of seggregating the listeners (the code has become really more verbose) better than what was being done in this PR earlier (merely seggregating the listeners as inbuilt and foreign) ? I feel that this implementation is shaping up to be more convoluted (atleast in the case of What exactly are we gaining by adding this complication ? |
37cd664
to
9588843
Compare
@juherr - I have addressed all the review comments. Please check now. |
9588843
to
4fef3c4
Compare
We learned that internal listeners must not be treated like user listeners because they are part of the logic. The next step will be to give a way for users to specify their own order logic. |
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.
Expect the too-precise name, everything else is great! 👍
testng-core-api/src/main/java/org/testng/internal/RuntimeBehavior.java
Outdated
Show resolved
Hide resolved
Maybe by having them annotated using a custom annotation ?
By default its taken care of via the JVM argument. |
testng-core/src/main/java/org/testng/internal/ListenerOrderDeterminer.java
Outdated
Show resolved
Hide resolved
Yes, it could be an option. |
e3fce2a
to
d30e588
Compare
So you are basically asking for a way to help a user inject how
I think |
@krmahadevan yes, that's exactly what I currently have in mind. |
@juherr Just to ensure that we don't forget this, I have created an issue for this. #2874 |
Hi @krmahadevan
In both cases, they are mixed with my listeners; the order is unpredictable. So issue #2771 is not solved. |
The listeners are being segregated into native and user listeners and then ordered such that the native listeners always get added at the end and the user defined listeners come in the front. This way we can ensure that whatever behaviour change was introduced by the user listeners get honoured by the native listeners ( user listener alters test state and that gets honoured by the native listener).
For this can you please try setting the JVM argument You can find the same in the documentation as well https://testng.org/#_jvm_arguments_in_testng |
Closes #2771
Fixes #2771 .
Did you remember to?
CHANGES.txt
./gradlew autostyleApply
We encourage pull requests that:
If your pull request involves fixing SonarQube issues then we would suggest that you please discuss this with the
TestNG-dev before you spend time working on it.
Note: For more information on contribution guidelines please make sure you refer our Contributing section for detailed set of steps.