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

Adds FreePort test extension #541

Closed
wants to merge 4 commits into from

Conversation

p1729
Copy link
Contributor

@p1729 p1729 commented Nov 15, 2021

Proposed commit message:

Adds extension for providing free port (#141 / #541)

This parameter resolution extension provides with a free port to test.

Closes: #141
PR: #541

PR checklist

The following checklist shall help the PR's author, the reviewers and maintainers to ensure the quality of this project.
It is based on our contributors guidelines, especially the "writing code" section.
It shall help to check for completion of the listed points.
If a point does not apply to the given PR's changes, the corresponding entry can be simply marked as done.

Documentation (general)

  • There is documentation (Javadoc and site documentation; added or updated)
  • There is implementation information to describe why a non-obvious source code / solution got implemented
  • Site documentation has its own .adoc file in the docs folder, e.g. docs/report-entries.adoc
  • Only one sentence per line (especially in .adoc files)
  • Javadoc uses formal style, while sites documentation may use informal style

Documentation (new extension)

  • The docs/docs-nav.yml navigation has an entry for the new extension
  • The package-info.java contains information about the new extension

Code

  • Code adheres to code style, naming conventions etc.
  • Successful tests cover all changes
  • There are checks which validate correct / false usage / configuration of a functionality and there are tests to verify those checks
  • Tests use AssertJ or our own PioneerAssert (which are based on AssertJ)

Contributing

  • A prepared commit message exists
  • The list of contributions inside README.md mentions the new contribution (real name optional)

I hereby agree to the terms of the JUnit Pioneer Contributor License Agreement.

@p1729 p1729 marked this pull request as ready for review November 15, 2021 17:55
@beatngu13
Copy link
Member

Hey @p1729,

Thx for your PR! We will look into this as soon as possible. ✌️

@Bukama Bukama linked an issue Dec 4, 2021 that may be closed by this pull request
Copy link
Member

@Bukama Bukama left a comment

Choose a reason for hiding this comment

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

Thank you for your PR and sorry for the delay in getting a response by our team.

Please add a documentation (under /docs folder) page which explains the (usage of) the extension and shows at least one use cases with example.

Maybe you can also write a small note in which cases this extension is different from solutions like the TestContainer project.

@p1729 p1729 changed the title adds free port extension to provide test with free port Adds free port extension Dec 5, 2021
@p1729 p1729 changed the title Adds free port extension Adds FreePort test extension Dec 5, 2021
@p1729
Copy link
Contributor Author

p1729 commented Dec 5, 2021

@Bukama Thanks. Could you please review the new changes, as I think I have fixed most of the requested changes.

@nipafx
Copy link
Member

nipafx commented Dec 9, 2021

Hi @p1729, I finally have some time to take a closer look at this. Let's see where it goes. 😃

@nipafx
Copy link
Member

nipafx commented Dec 9, 2021

After going over this PR (which looks really good, btw), I eventually noticed that there's likely some overlap with the more general resource mechanism that we're building in #348/#491. It seems to me that a port would be a fitting resource. So instead of merging this PR now and then later having to retrofit the extension to work with the new mechanism (if that makes sense), I'd rather put this on hold until we know more on that front.

I'm really sorry that the time and effort you invested will not lead to a merged PR for now. You clearly went over the contribution guide and wrote good docs and I'm thankful for that. It sucks that we're just gonna let this sit for some time, but I hope you understand. :)

@nipafx nipafx marked this pull request as draft December 9, 2021 19:00
@p1729
Copy link
Contributor Author

p1729 commented Dec 11, 2021

@nipafx Not a problem. Keep me apprised of the things related to this PR.

@nipafx
Copy link
Member

nipafx commented Apr 10, 2022

@p1729 Just a quick update: I didn't forget about this. #491 is progressing and mostly it's just documentation that's left over. I hope you'll be able to try the API for this extension within a month or two. 🤞🏾

Copy link
Member

@Michael1993 Michael1993 left a comment

Choose a reason for hiding this comment

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

Thank you for your contribution @p1729! This looks super.
That said, I do have a couple notes here. 🧐

Behaviour

  • We generally prefer to create our own annotation instead of @ExtendWith. This is especially useful if you need to pass certain parameters to your extension (which we probably want to do - see next points).
  • In the linked issue the recommended behaviour of this extension is is to be able to designate a "strategy" class. For example an annotation with a strategy property is a good approach.
  • The extension assigns a free port number rather eagerly, i.e. when you create your FreePort instance - I think this is... fine? But I'd rather have another option available: only assign the port number when the user calls the get or number methods. (Could also be in the annotation as lazy = true)
  • Also, why not just return with the ServerSocket? We can document that in this case the extension does not handle the closing and the user should use a try-with-resources statement.

Tests

The tests need to be expanded - now it basically tests the bare minimum. For example, I'd want to see it handle the port not being available with isFreeNow.

This is a splendid first approach. You might have been waiting for #491 to be merged before expanding this (Which is still not merged... that's on us. 😬). You might also have been waiting for some detailed feedback (again, on us. 😬). Either way, I wanted to give you this feedback in hopes we will merge #491 soon (to let you start working on it as soon as you want). 🤞

import java.io.IOException;
import java.net.ServerSocket;

public final class FreePort {
Copy link
Member

Choose a reason for hiding this comment

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

Why is this final?

== Introduction

Sometimes we want a free port in our tests so that we can either start a server on it or
to test a failure scenario when there is no service at given port.
Copy link
Member

Choose a reason for hiding this comment

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

We use the "one sentence per line" rule - helps us keep our documentation simple.

@Michael1993
Copy link
Member

Hi again @p1729 ! #491 finally got merged - could you let us know if you are still interested in working on this?

@nipafx
Copy link
Member

nipafx commented Nov 14, 2022

We've finally merged support for resources! 🥳 You can learn all about it here:

This extension should use the same mechanism, which requires a major refactoring.

@p1729: Are you interested to do this? If not, that's ok, too, then somebody else will tackle it.

@p1729
Copy link
Contributor Author

p1729 commented Nov 14, 2022

@nipafx / @Michael1993 I'm interested and will refactor as per the new design soon.

@nipafx
Copy link
Member

nipafx commented Nov 14, 2022

Cool! Looking forward to it. :)

@Michael1993
Copy link
Member

Hi again @p1729 ! Just checking in if you might want to let someone else tackle this if you don't have the time?

@p1729
Copy link
Contributor Author

p1729 commented Mar 9, 2023

@Michael1993 Sure, pls go ahead.

@nipafx
Copy link
Member

nipafx commented Nov 9, 2023

I think two years after opening the PR, it's safe to close it. Sorry @p1729 that we let you down and didn't get around to including your contribution. 😔

@nipafx nipafx closed this Nov 9, 2023
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.

Add a FreePort extension
5 participants