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

Provide JenkinsRule.restart() implementation #716

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

strangelookingnerd
Copy link

@strangelookingnerd strangelookingnerd commented Jan 17, 2024

Background

Thanks to #438 there is now support for JUnit5. However there are still some open points or missing features from JUnit4 evolving around JenkinsRule.

Problem

While trying to upgrade the plugin archetypes to use JUnit5 (jenkinsci/archetypes#691) I encountered one of these open points: Right now there is no implementation that resembles RestartableJenkinsRule or JenkinsSessionRule for JUnit5.

After giving it a try myself to get such an implementation going I quickly found that it will likely require a huge portion of refactoring and changing behavior of JenkinsRule / JUnit5JenkinsRule.

Even though I do think that at some point one might need to bite the bullet and fully re-write most of the implementation for JUnit5 and dropping support for JUnit4 - this is not my decision to make and more importantly I would not want to jump onto that unless that decision is made beforehand 😄

Solution

Anyways, since I still wanted to find some equivalent for RestartableJenkinsRule or JenkinsSessionRule I opted for an extension to JenkinsRule by providing JenkinsRule.restart(). This method basically does the same as the JUnit4 rules but is agnostic to the JUnit version being used.
Summed up shorty it creates a backup of the JENKINS_HOME and restarts the underlying Jenkins instance by running JenkinsRule.after() and JenkinsRule.before() with the backup as home. The port remains unchanged.

From what I can tell this method could be used in favor of RestartableJenkinsRule or JenkinsSessionRule in most of the existing test cases:

This would allow these projects to migrate to JUnit5 eventually without any downside and would open up the way to deprecate / discontinue the usage of JUnit4 in jenkinsci.

@basil: FYI

Testing done

  • Added new tests that demonstrate that JenkinsRule.restart() works for JUnit4 as well as JUnit5.
  • Added additional tests for the resolution of JUnit5JenkinsRule because I found them useful to have.

Submitter checklist

@strangelookingnerd strangelookingnerd force-pushed the feature/provide_restart_for_jenkins_rule branch from 3b50059 to 3488f8d Compare January 17, 2024 17:20
@strangelookingnerd strangelookingnerd force-pushed the feature/provide_restart_for_jenkins_rule branch from 3488f8d to ba496ee Compare April 11, 2024 13:19
@strangelookingnerd strangelookingnerd force-pushed the feature/provide_restart_for_jenkins_rule branch from ba496ee to a53638d Compare April 17, 2024 16:36
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.

1 participant