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

Forward compatibility with Jetty 10 in JenkinsRule #455

Merged
merged 1 commit into from
Jul 11, 2022

Conversation

basil
Copy link
Member

@basil basil commented Jul 7, 2022

Required for jenkinsci/jenkins#6805, #453, jenkinsci/jenkins#6802.

Problem

When the application is started from java -jar jenkins.war, hudson.WebAppMain runs to initialize the application. In the context of the test harness, we do not want this to happen, since the test harness initializes Jenkins itself.

The current method does this with a call to context.setEventListeners(null) in NoListenerConfiguration. This has three problems:

  1. It is final, forcing the need for copypasta in https://github.com/jenkinsci/jenkins/blob/6de288f424f3a76d9fab9e54e379ca171b08e158/test/src/test/java/hudson/util/BootFailureTest.java#L79-L80=.
  2. It does not work in Jetty 10, causing opaque test failures in JenkinsRuleTest.
  3. It not only clears the listener for hudson.WebAppMain, which is its purpose, but it also clears all other listeners, including other valuable cleanup listeners. The current (ordered) list of listeners in Jetty 9 is:
  • org.eclipse.jetty.servlet.listener.ELContextCleaner
  • org.eclipse.jetty.servlet.listener.IntrospectorCleaner
  • jenkins.util.SystemProperties.Listener
  • hudson.WebAppMain (needs to be cleared in the test harness)
  • jenkins.JenkinsHttpSessionListener

Solution

We make the class non-final and remove only the WebAppMain listener. This fixes all three problems:

  1. The copypasta can be removed in https://github.com/jenkinsci/jenkins/blob/6de288f424f3a76d9fab9e54e379ca171b08e158/test/src/test/java/hudson/util/BootFailureTest.java#L79-L80=.
  2. JenkinsRuleTest starts working in Jetty 10.
  3. The other listeners run. As of Jetty 10, the new (ordered) list of listeners is:
  • org.eclipse.jetty.websocket.core.server.WebSocketServerComponentsCleanupListener
  • org.eclipse.jetty.websocket.server.JettyWebSocketServerContainer
  • org.eclipse.jetty.websocket.server.JettyWebSocketServerContainerCleanupListener
  • org.eclipse.jetty.servlet.listener.ELContextCleaner
  • org.eclipse.jetty.servlet.listener.IntrospectorCleaner
  • jenkins.util.SystemProperties.Listener
  • hudson.WebAppMain (needs to be cleared in the test harness)
  • jenkins.JenkinsHttpSessionListener
  • org.eclipse.jetty.server.AllowedResourceAliasChecker.AllowedResourceAliasCheckListener

Testing done

I tested this with BootFailureTest in core with both Jetty 9 (jenkinsci/jenkins#6805) and Jetty 10 (jenkinsci/jenkins#6802).

protected void doStart() {
for (EventListener eventListener : context.getEventListeners()) {
if (eventListener instanceof WebAppMain) {
context.removeEventListener(eventListener);
Copy link
Member

Choose a reason for hiding this comment

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

So this isn't causing a ConcurrentModificationException?

Copy link
Member Author

Choose a reason for hiding this comment

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

No. The internal data structure is a CopyOnWriteArrayList.

@rsandell rsandell merged commit 9de0d87 into jenkinsci:master Jul 11, 2022
@basil basil deleted the NoListenerConfiguration branch July 11, 2022 15:34
basil added a commit to basil/jenkins that referenced this pull request Jul 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants