Skip to content

Added MILL_TEST_FREE_PORT #4931

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

Draft
wants to merge 27 commits into
base: main
Choose a base branch
from
Draft

Added MILL_TEST_FREE_PORT #4931

wants to merge 27 commits into from

Conversation

albassort
Copy link

Made in accordance to #3802

@albassort albassort marked this pull request as ready for review April 13, 2025 21:22
@albassort
Copy link
Author

RE: There is some failing tests on HEAD right now. I think

Run Tests / windows (17.0.14, 'integration.bootstrap[no-java-bootstrap].native.server') / run (pull_request)Failing after 9m

Might be related to the PR but im not sure. I will be investigating,

Comment on lines 55 to 58
/**
* Used to store free ports for Mill's tests to use.
*/
public static final String MILL_TEST_FREE_PORT = "MILL_TEST_FREE_PORT";
Copy link
Member

Choose a reason for hiding this comment

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

Is this a single port or multiple. The comment is a bit vague. If it is multi, that the variable should be MILL_TEST_FREE_PORTS and we should document here, which separator is used.

var i = 0
var ports = Set.empty[Int]
for (_ <- 1 to 100) {
if (i == 6) {
Copy link
Member

Choose a reason for hiding this comment

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

Magic number 6! A parameter or a named constant might be better.

@lihaoyi
Copy link
Member

lihaoyi commented Apr 18, 2025

This doesn't satisfy the original issue

The end result is that Mill's own example suite can remove all hardcoded ports and replace them with usages of the MILL_TEST_FREE_PORT environment variable

@albassort
Copy link
Author

albassort commented Apr 18, 2025

This doesn't satisfy the original issue

The end result is that Mill's own example suite can remove all hardcoded ports and replace them with usages of the MILL_TEST_FREE_PORT environment variable

I misunderstood, I thought that were to be done in a second PR. I will work on this.

@albassort albassort marked this pull request as draft April 18, 2025 22:07
@albassort albassort marked this pull request as ready for review April 29, 2025 17:29
@albassort
Copy link
Author

albassort commented Apr 29, 2025

@lihaoyi @lefou

So there is numerous limitations with what I have here.

  1. The PR uses the PORT environmental variable
  2. Ports are ephemeral with no central manager for the following reasons
    1. The desire to have it in a ExternalModule, any build.mill can access the code
    2. The lack of any existing central manager for Tasks as well was UTestManager
    3. The lack of access to the ExecutionContext from the UTestManager
  3. Only works for UTESTFramework

I experimented with adding some code in ExecutionImpl, thats where it could be managed if I knew

  1. How I can add such env variable from GroupExecute or Execute0. There the ExecutionContext can be modified
  2. How to route the ExecutionContext into UTestFramework. From what I can tell, there is no way
  3. How I can coordinate from all parts of the code to a specific location easily. This is also an issue in my other PR. I have no way of getting the out/ folder from all parts in the codebase, so I cant move the code to the testkit or server or runner and use a lock to coordinate ports over a JSON port.

Still, you can easily add some code to Task.Command {} (and I did) To allow a centrally managed Port dispatcher for those


Regardless, I did manage to replace hard coded ports for most of the TESTS. However, there is still the chance there can be conflicting ports.

@lihaoyi
Copy link
Member

lihaoyi commented May 5, 2025

I must admit I am having trouble following the code. There's a bunch of random "!" strings, an apparently unused MILL_TEST_FREE_PORT variable, and other things.

As far as I can tell, the current implementation is unique to UTestExampleTestSuite. We should try and make it work with any Task with some kind of ports = true or ports = 1 flag, so it's useful to users as ewll

@albassort
Copy link
Author

I must admit I am having trouble following the code. There's a bunch of random "!" strings, an apparently unused MILL_TEST_FREE_PORT variable, and other things.

As far as I can tell, the current implementation is unique to UTestExampleTestSuite. We should try and make it work with any Task with some kind of ports = true or ports = 1 flag, so it's useful to users as ewll

I will mark as WIP until I figure out a way to make it work with all Tasks

@albassort albassort marked this pull request as draft May 5, 2025 06:41
Removed unused envvar
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.

3 participants