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

[JENKINS-72387] Provide JUnit5 Class (static) context for JenkinsRule #689

Merged
merged 3 commits into from
Nov 29, 2023

Conversation

bstopp
Copy link
Contributor

@bstopp bstopp commented Nov 28, 2023

See JENKINS-72387.

I'd like to add support for creating one running Jenkins instance per Test Class, when using the JUnit5 extension points.

Due to how the JenkinsRule and underlying contexts expect population of the Jenkins testDescription, some refactoring of was required. This was necessary to find all annotations that may exist in all contexts - which would define the pre-test state of the Jenkins instance.

Testing done

All previous tests pass, including the original which tested code this PR has refactored/modified (JenkinsRuleResolverTest).
Added an additional test (JenkinsRuleClassResolverTest) to ensure the explicit feature was validated.

Submitter checklist

Edit tasklist title
Beta Give feedback Tasklist Submitter checklist, more options

Delete tasklist

Delete tasklist block?
Are you sure? All relationships in this tasklist will be removed.
  1. Make sure you are opening from a topic/feature/bugfix branch (right side) and not your main branch!
    Options
  2. Ensure that the pull request title represents the desired changelog entry
    Options
  3. Please describe what you did
    Options
  4. Link to relevant issues in GitHub or Jira
    Options
  5. Link to relevant pull requests, esp. upstream and downstream changes
    Options
  6. Ensure you have provided tests - that demonstrates feature works or fixes the issue
    Options

@WithJenkins
class JenkinsRuleClassResolverTest {

static JenkinsRule rule;
Copy link
Member

Choose a reason for hiding this comment

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

Rather than reflection would it be cleaner to explicitly register it do you think?
https://junit.org/junit5/docs/current/user-guide/#extensions-registration-programmatic

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was trying to avoid having different solutions for the different contexts.

@WithJenkins on the class or method gets you test-method parameter injection. Having a different approach for the class test context creates additional complexity for the consuming devs.

@timja timja merged commit 0d2b4aa into jenkinsci:master Nov 29, 2023
14 checks passed
@bstopp bstopp deleted the feat/class-rule branch November 29, 2023 13:12
@basil
Copy link
Member

basil commented Jan 10, 2024

[ERROR] io.jenkins.plugins.fontawesome.SvgTagITest -- Time elapsed: 5.511 s <<< ERROR!
org.junit.jupiter.api.extension.ParameterResolutionException: Failed to bind to localhost/127.0.0.1:36687
        at org.jvnet.hudson.test.junit.jupiter.JenkinsExtension.resolveParameter(JenkinsExtension.java:107)
        at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
        Suppressed: java.lang.IllegalStateException: Jenkins.instance is missing. Read the documentation of Jenkins.getInstanceOrNull to see what you are doing wrong.
                at jenkins.model.Jenkins.get(Jenkins.java:814)
                at org.jvnet.hudson.test.RemainingActivityListener.problem(RemainingActivityListener.java:71)
                at org.jvnet.hudson.test.RemainingActivityListener.onTearDown(RemainingActivityListener.java:59)
                at org.jvnet.hudson.test.JenkinsRule.after(JenkinsRule.java:499)
                at org.jvnet.hudson.test.junit.jupiter.JenkinsExtension.afterAll(JenkinsExtension.java:70)
                ... 1 more
Caused by: java.io.IOException: Failed to bind to localhost/127.0.0.1:36687
        at org.eclipse.jetty.server.ServerConnector.openAcceptChannel(ServerConnector.java:344)
        at org.eclipse.jetty.server.ServerConnector.open(ServerConnector.java:304)
        at org.eclipse.jetty.server.Server.lambda$doStart$0(Server.java:402)
        at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:184)
        at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
        at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:179)
        at java.base/java.util.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:1024)
        at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
        at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
        at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:151)
        at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:174)
        at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
        at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:596)
        at org.eclipse.jetty.server.Server.doStart(Server.java:398)
        at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:93)
        at org.jvnet.hudson.test.JenkinsRule._createWebServer(JenkinsRule.java:885)
        at org.jvnet.hudson.test.JenkinsRule.createWebServer(JenkinsRule.java:803)
        at org.jvnet.hudson.test.JenkinsRule.createWebServer(JenkinsRule.java:791)
        at org.jvnet.hudson.test.JenkinsRule.newHudson(JenkinsRule.java:741)
        at org.jvnet.hudson.test.JenkinsRule.before(JenkinsRule.java:409)
        at org.jvnet.hudson.test.junit.jupiter.JenkinsExtension.resolveParameter(JenkinsExtension.java:104)
        ... 1 more
Caused by: java.net.BindException: Address already in use
        at java.base/sun.nio.ch.Net.bind0(Native Method)
        at java.base/sun.nio.ch.Net.bind(Net.java:565)
        at java.base/sun.nio.ch.ServerSocketChannelImpl.netBind(ServerSocketChannelImpl.java:344)
        at java.base/sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:301)
        at org.eclipse.jetty.server.ServerConnector.openAcceptChannel(ServerConnector.java:339)
        ... 21 more

with similar failures in io.jenkins.plugins.forensics.blame.BlamerFactoryITest, io.jenkins.plugins.forensics.delta.DeltaCalculatorFactoryITest, io.jenkins.plugins.forensics.miner.MinerFactoryITest, and io.jenkins.plugins.forensics.reference.SimpleReferenceRecorderITest

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

3 participants