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

Closed
wants to merge 27 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
5ed3b21
Added a Port cli option
Apr 13, 2025
9e6a6b2
Merge remote-tracking branch 'upstream/main' into ports
Apr 13, 2025
1e8fcfc
Added the EnvVar, and renamed the one in MillMain to be named properly
Apr 13, 2025
c653c4f
[autofix.ci] apply automated fixes
autofix-ci[bot] Apr 13, 2025
7c16274
added a small test
Apr 13, 2025
fcb906e
Removed needless println
Apr 15, 2025
24dc402
Clarified some things, added a const for target
Apr 15, 2025
52551bc
[autofix.ci] apply automated fixes
autofix-ci[bot] Apr 15, 2025
6cc4367
Accidentally repeated a line
Apr 15, 2025
a038193
Merge branch 'main' into ports
albassort Apr 16, 2025
71fc484
[autofix.ci] apply automated fixes
autofix-ci[bot] Apr 16, 2025
27a876d
Added PortManager external module and changed a lot of tests
Apr 26, 2025
bbb99ef
deleted duplicate
Apr 27, 2025
cc893ab
typo
Apr 27, 2025
e2f0250
fixed a broken test
Apr 27, 2025
77499c5
temporary revert
Apr 27, 2025
fc62b82
fixed a test
Apr 27, 2025
4b682ed
Removed dead code
Apr 29, 2025
21873fd
Merge remote-tracking branch 'upstream/main' into ports
Apr 29, 2025
8c312bd
[autofix.ci] apply automated fixes
autofix-ci[bot] Apr 29, 2025
4c74e9f
resetting stray changes (1?)
Apr 29, 2025
3d47359
fixed some broken tests
Apr 29, 2025
014d164
Merge branch 'main' into ports
albassort Apr 29, 2025
6511b51
[autofix.ci] apply automated fixes
autofix-ci[bot] Apr 29, 2025
6d7d58b
forgort to set port
Apr 29, 2025
646ede7
Merge branch 'ports' of https://github.com/albassort/mill into ports
Apr 29, 2025
c5dc53d
Update EnvVars.java
albassort May 9, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/exec/src/mill/exec/GroupExecution.scala
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ private trait GroupExecution {
)
}
}

case task =>
val (newResults, newEvaluated) = executeGroup(
group = group,
Expand Down Expand Up @@ -256,7 +257,6 @@ private trait GroupExecution {
deps: Seq[Task[?]],
offline: Boolean
): (Map[Task[?], ExecResult[(Val, Int)]], mutable.Buffer[Task[?]]) = {

val newEvaluated = mutable.Buffer.empty[Task[?]]
val newResults = mutable.Map.empty[Task[?], ExecResult[(Val, Int)]]

Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
server.port=8084
server.port=8084
4 changes: 3 additions & 1 deletion example/javalib/web/2-hello-spring-boot/build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ object `package` extends JavaModule {
> mill test
...com.example.HelloSpringBootTest#shouldReturnDefaultMessage() finished...

> echo "server.port=$PORT" >> ./resources/application.properties

> mill runBackground

> curl http://localhost:8086
> curl http://localhost:$PORT
...<h1>Hello, World!</h1>...

> mill clean runBackground
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
server.port=8086
4 changes: 3 additions & 1 deletion example/javalib/web/4-hello-micronaut/build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,11 @@ trait MicronautModule extends MavenModule {
> mill test
...example.micronaut.HelloControllerTest#testHello()...

> echo "micronaut.server.port=$PORT" >> ./src/main/resources/application.properties

> mill runBackground

> curl http://localhost:8088/hello
> curl "http://localhost:$PORT/hello"
...Hello World...

> mill clean runBackground
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
#Tue Jun 18 12:49:41 UTC 2024
micronaut.application.name=default
micronaut.server.port=8088
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@ object server extends TypeScriptModule {
super.resources() ++ Seq(PathRef(Task.dest))
}

override def forkEnv = super.forkEnv() + ("PORT" -> "4000")

object test extends TypeScriptTests with TestModule.Cypress {
def service = server
def port = "4000"
def port = sys.env.get("PORT").get
}
}

Expand All @@ -32,7 +30,6 @@ object server extends TypeScriptModule {

> mill server.test
...
...Server listening on port 4000
... app.cy.ts...
... All specs passed!...
...
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// @ts-nocheck
import { defineConfig } from 'cypress';

const port = process.env.PORT
export default defineConfig({
e2e: {
specPattern: '**/e2e/*.cy.ts',
baseUrl: 'http://localhost:4000',
supportFile: false
}
});
e2e: {
specPattern: '**/e2e/*.cy.ts',
baseUrl: `http://localhost:${port}`,
supportFile: false
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@ object server extends TypeScriptModule {
super.resources() ++ Seq(PathRef(Task.dest))
}

def forkEnv = super.forkEnv() + ("PORT" -> "3000")

object test extends TypeScriptTests with TestModule.PlayWright {
def service = server
def port = "6000"
def port = sys.env.get("PORT").get
}
}

Expand All @@ -32,8 +30,6 @@ object server extends TypeScriptModule {

> mill server.test
...
...Server listening on port 6000
...
...1 passed...
...
*/
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
import {defineConfig} from '@playwright/test';
import { defineConfig } from '@playwright/test';
import * as glob from 'glob';
import * as path from 'path';

const testFiles = glob.sync('**/playwright/*.test.ts', {absolute: true});
const testFiles = glob.sync('**/playwright/*.test.ts', { absolute: true });

const port = process.env.PORT

export default defineConfig({
testDir: './',
testMatch: testFiles.map(file => path.relative(process.cwd(), file)),
timeout: 30000,
retries: 1,
use: {
baseURL: 'http://localhost:6000',
headless: true,
trace: 'on-first-retry',
launchOptions: {
args: ['--explicitly-allowed-ports=6000']
},
channel: 'chrome', // Use the stable Chrome channel
testDir: './',
testMatch: testFiles.map(file => path.relative(process.cwd(), file)),
timeout: 30000,
retries: 1,
use: {
baseURL: `http://localhost:${port}`,
headless: true,
trace: 'on-first-retry',
launchOptions: {
args: ['--explicitly-allowed-ports=6000']
},
projects: [
{
name: 'chromium',
use: {browserName: 'chromium'}
}
]
});
channel: 'chrome', // Use the stable Chrome channel
},
projects: [
{
name: 'chromium',
use: { browserName: 'chromium' }
}
]
});
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import express, {Express} from 'express';
import express, { Express } from 'express';
import cors from 'cors';

const Resources: string = (process.env.RESOURCESDEST || "@server/resources") + "/build" // `RESOURCES` is generated on bundle
const Client = require.resolve(`${Resources}/index.html`);

const app: Express = express();
const port = process.env.PORT || 3001;
const port = process.env.PORT
const BuildPath = Client.replace(/index\.html$/, "");

app.use(cors());
Expand All @@ -15,7 +15,7 @@ app.use(express.json());
app.use(express.static(BuildPath));

app.listen(port, () => {
console.log(`Server listening on port ${port}`);
console.log(`Server listening on port ${port}`);
});

export default app;
export default app;
2 changes: 1 addition & 1 deletion example/kotlinlib/web/1-hello-ktor/build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Test com.example.HelloKtorTest HelloKtorTest finished, took...

> mill runBackground

> curl http://localhost:8090
> curl http://localhost:$PORT
...<h1>Hello, World!</h1>...

> mill clean runBackground
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import io.ktor.server.routing.get
import io.ktor.server.routing.routing

fun main() {
embeddedServer(Netty, port = 8090, host = "0.0.0.0", module = Application::module)
embeddedServer(Netty, port = System.getenv("PORT").toInt(), host = "0.0.0.0", module = Application::module)
.start(wait = true)
}

Expand Down
2 changes: 1 addition & 1 deletion example/kotlinlib/web/2-todo-ktor/build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ object `package` extends KotlinModule {

> mill runBackground

> curl http://localhost:8091
> curl http://localhost:$PORT
...<h1>todos</h1>...

> mill clean runBackground
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import org.thymeleaf.templateresolver.ClassLoaderTemplateResolver
fun main(args: Array<String>) {
val database = Database.connect("jdbc:h2:mem:regular;DB_CLOSE_DELAY=-1;", "org.h2.Driver")
val todoItemRepository = TodoItemRepositoryImpl(database)
embeddedServer(Netty, port = 8091, host = "0.0.0.0") {
embeddedServer(Netty, port = System.getenv("PORT").toInt(), host = "0.0.0.0") {
app(todoItemRepository)
}.start(wait = true)
}
Expand Down
4 changes: 2 additions & 2 deletions example/kotlinlib/web/4-webapp-kotlinjs/build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ object `package` extends KotlinModule {

> ./mill runBackground

> curl http://localhost:8092
> curl http://localhost:$PORT
...What needs to be done...
...

> curl http://localhost:8092/static/client.js
> curl http://localhost:$PORT/static/client.js
...bindEvent(this, 'todo-all', '/list/all', 'all')...
...

Expand Down
2 changes: 1 addition & 1 deletion example/kotlinlib/web/4-webapp-kotlinjs/src/WebApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ object WebApp {

@JvmStatic
fun main(args: Array<String>) {
embeddedServer(Netty, port = 8092, host = "0.0.0.0") {
embeddedServer(Netty, port = System.getenv("PORT").toInt(), host = "0.0.0.0") {
configureRoutes(this)
}.start(wait = true)
}
Expand Down
4 changes: 2 additions & 2 deletions example/kotlinlib/web/5-webapp-kotlinjs-shared/build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,11 @@ object `package` extends AppKotlinModule {

> ./mill runBackground

> curl http://localhost:8093
> curl http://localhost:$PORT
...What needs to be done...
...

> curl http://localhost:8093/static/client.js
> curl http://localhost:$PORT/static/client.js
...kotlin.js...
...

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ object WebApp {

@JvmStatic
fun main(args: Array<String>) {
embeddedServer(Netty, port = 8093, host = "0.0.0.0") {
embeddedServer(Netty, port = System.getenv("PORT").toInt(), host = "0.0.0.0") {
install(ContentNegotiation) {
json()
}
Expand Down
4 changes: 3 additions & 1 deletion example/kotlinlib/web/6-hello-spring-boot/build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ object `package` extends KotlinModule {
> mill test
...com.example.HelloSpringBootTest#shouldReturnDefaultMessage() finished...

> echo "server.port=$PORT" >> ./resources/application.properties

> mill runBackground

> curl http://localhost:8095
> curl http://localhost:$PORT
...<h1>Hello, World!</h1>...

> mill clean runBackground
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
server.port=8095
server.port=8095
4 changes: 2 additions & 2 deletions example/pythonlib/web/1-hello-flask/build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ object foo extends PythonModule {

// Running these commands will test and run the Flask server with desired outputs.

// The app is ready to serve at `http://localhost:5000`.
// The app is ready to serve at `http://localhost:$PORT`.

/** Usage

Expand All @@ -31,7 +31,7 @@ OK

> ./mill foo.runBackground

> curl http://localhost:5000
> curl http://localhost:$PORT
...<h1>Hello, Mill!</h1>...

> ./mill clean foo.runBackground
Expand Down
4 changes: 3 additions & 1 deletion example/pythonlib/web/1-hello-flask/foo/src/foo.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from flask import Flask
import os

app = Flask(__name__)

Expand All @@ -9,4 +10,5 @@ def hello_world():


if __name__ == "__main__":
app.run(debug=True)
port = os.environ['PORT']
app.run(debug=True, port = port)
6 changes: 3 additions & 3 deletions example/pythonlib/web/3-hello-django/build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ object foo extends PythonModule {

}
// Using `Mill`, we can easily manage dependencies, run `Django tests`, and `launch the server`.
// With just a few commands, the app is ready to serve at `http://localhost:5002`.
// With just a few commands, the app is ready to serve at `http://localhost:$PORT`.

/** Usage

Expand All @@ -26,9 +26,9 @@ Ran 1 test...
OK
...

> ./mill foo.runBackground runserver 5002
> ./mill foo.runBackground runserver $PORT

> curl http://localhost:5002
> curl http://localhost:$PORT
...<h1>Hello, Mill!</h1>...

> ./mill clean foo.runBackground
Expand Down
4 changes: 2 additions & 2 deletions example/pythonlib/web/4-todo-django/build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ test_toggle_todo_view (main.tests.TodoAppTests...) ... ok
...Ran 8 tests...
...OK...

> ./mill todo.runBackground runserver 5003
> ./mill todo.runBackground runserver $PORT

> curl http://localhost:5003
> curl http://localhost:$PORT
...What needs to be done...

> ./mill clean todo.runBackground
Expand Down
2 changes: 1 addition & 1 deletion example/scalalib/web/1-todo-webapp/build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ object `package` extends ScalaModule {

> ./mill runBackground

> curl http://localhost:8080
> curl http://localhost:$PORT
...What needs to be done...
...

Expand Down
2 changes: 2 additions & 0 deletions example/scalalib/web/1-todo-webapp/src/WebApp.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import scalatags.Text.all._
import scalatags.Text.tags2

object WebApp extends cask.MainRoutes {
override def port = sys.env.get("PORT").getOrElse("!").toInt

case class Todo(checked: Boolean, text: String)

object Todo {
Expand Down
6 changes: 4 additions & 2 deletions example/scalalib/web/1-todo-webapp/test/src/WebAppTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ package webapp
import utest._

object WebAppTests extends TestSuite {
val port = sys.env.get("PORT").getOrElse("!").toInt

def withServer[T](example: cask.main.Main)(f: String => T): T = {
val server = io.undertow.Undertow.builder
.addHttpListener(8181, "localhost")
.addHttpListener(port, "localhost")
.setHandler(example.defaultHandler)
.build
server.start()
val res =
try f("http://localhost:8181")
try f(s"http://localhost:$port")
finally server.stop()
res
}
Expand Down
Loading