Skip to content

Commit 6031437

Browse files
authored
acc: Use fixed ports instead of dynamically allocated ones for run-local tests (#3490)
## Changes Use fixed ports instead of dynamically allocated ones for run-local tests ## Why After researching and trying to stabilize the tests, I concluded that dynamic port allocation is likely the root cause of its flakiness. The hypothesis is that `allocate_ports.py` calls socket.close() after finding a free port. When the socket is closed, the port it was using is released back to the OS. However, the port does not become instantly available for another application to use. It typically enters a TIME_WAIT state to handle any stray packets. It could be that the "connection refused" error, which happens when the curl command tries to connect after the Python script has closed the socket, but before the app has successfully bound to the port and is ready to accept connections ## Tests After making ports fixed in the script, all tests for all runners succeeded (tried 5 times) <!-- If your PR needs to be included in the release notes for next release, add a separate entry in NEXT_CHANGELOG.md as part of your PR. -->
1 parent d86b288 commit 6031437

File tree

7 files changed

+28
-45
lines changed

7 files changed

+28
-45
lines changed

acceptance/bin/allocate_ports.py

Lines changed: 0 additions & 22 deletions
This file was deleted.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
Local = false
1+
Local = true
22
Cloud = false
33

44
[EnvMatrix]
5-
DATABRICKS_CLI_DEPLOYMENT = ["terraform", "direct-exp"]
5+
DATABRICKS_CLI_DEPLOYMENT = ["terraform"]

acceptance/cmd/workspace/apps/run-local-node/script

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,9 @@ cd app
44
# so we don't need to start it in background. It will install the dependencies as part of the command
55
trace $CLI apps run-local --prepare-environment --entry-point test.yml 2>&1 | grep -w "Hello, world"
66

7-
# Get 3 unique ports sequentially to avoid conflicts
8-
PORTS=$(allocate_ports.py 3 | tr -d '\r')
9-
10-
# Read ports into array
11-
PORTS_ARR=($(echo "$PORTS"))
12-
PORT="${PORTS_ARR[0]}"
13-
DEBUG_PORT="${PORTS_ARR[1]}"
14-
PROXY_PORT="${PORTS_ARR[2]}"
7+
PORT=8080
8+
DEBUG_PORT=5252
9+
PROXY_PORT=8081
1510

1611
title "Starting the app in background..."
1712
trace $CLI apps run-local --prepare-environment --debug --port "$PROXY_PORT" --debug-port "$DEBUG_PORT" --app-port "$PORT" > ../out.run.txt 2>&1 &
@@ -28,6 +23,11 @@ while [ -z "$(grep -o "Server is running on port " out.run.txt 2>/dev/null)" ];
2823
sleep 1
2924
done
3025

26+
# Make sure the proxy is ready to serve requests
27+
while [ -z "$(grep -o "To access your app go to " out.run.txt 2>/dev/null)" ]; do
28+
sleep 1
29+
done
30+
3131
title "Checking app is running..."
3232
trace curl -s -o - http://127.0.0.1:$PROXY_PORT | grep -w "Hello From App"
3333

acceptance/cmd/workspace/apps/run-local-node/test.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
# Temporarily disabled due to the flakiness like here https://github.com/databricks/cli/actions/runs/17234131593/job/48894892423
21
Cloud = false
3-
Local = false
2+
Local = true
43
RecordRequests = false
54
Timeout = '2m'
65
TimeoutWindows = '10m'
@@ -21,3 +20,6 @@ New='127.0.0.1:$(port)'
2120
[[Repls]]
2221
Old='To debug your app, attach a debugger to port [0-9]+'
2322
New='To debug your app, attach a debugger to port $(debug_port)'
23+
24+
[EnvMatrix]
25+
DATABRICKS_CLI_DEPLOYMENT = ["terraform"]
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
Local = false
1+
Local = true
22
Cloud = false
33

44
[EnvMatrix]
5-
DATABRICKS_CLI_DEPLOYMENT = ["terraform", "direct-exp"]
5+
DATABRICKS_CLI_DEPLOYMENT = ["terraform"]

acceptance/cmd/workspace/apps/run-local/script

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,9 @@ trace errcode $CLI apps run-local --entry-point value-from.yml 2>&1
66
# so we don't need to start it in background. It will install the dependencies as part of the command
77
trace $CLI apps run-local --prepare-environment --entry-point test.yml 2>&1 | grep -w "Hello, world"
88

9-
# Get 3 unique ports sequentially to avoid conflicts
10-
PORTS=$(allocate_ports.py 3 | tr -d '\r')
11-
12-
# Read ports into array
13-
PORTS_ARR=($(echo "$PORTS"))
14-
PORT="${PORTS_ARR[0]}"
15-
DEBUG_PORT="${PORTS_ARR[1]}"
16-
PROXY_PORT="${PORTS_ARR[2]}"
9+
PORT=8080
10+
DEBUG_PORT=5252
11+
PROXY_PORT=8081
1712

1813
title "Starting the app in background..."
1914
trace $CLI apps run-local --prepare-environment --debug --port "$PROXY_PORT" --debug-port "$DEBUG_PORT" --app-port "$PORT" > ../out.run.txt 2>&1 &
@@ -30,6 +25,11 @@ while [ -z "$(grep -o "Python Flask app has started with" out.run.txt 2>/dev/nul
3025
sleep 1
3126
done
3227

28+
# Make sure the proxy is ready to serve requests
29+
while [ -z "$(grep -o "To access your app go to " out.run.txt 2>/dev/null)" ]; do
30+
sleep 1
31+
done
32+
3333
title "Checking app is running..."
3434
trace curl -s -o - http://127.0.0.1:$PROXY_PORT | jq
3535

acceptance/cmd/workspace/apps/run-local/test.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Cloud = false
2-
Local = false
2+
Local = true
33
RecordRequests = false
44
Timeout = '2m'
55
TimeoutWindows = '10m'
@@ -20,3 +20,6 @@ New='127.0.0.1:$(port)'
2020
[[Repls]]
2121
Old='To debug your app, attach a debugger to port [0-9]+'
2222
New='To debug your app, attach a debugger to port $(debug_port)'
23+
24+
[EnvMatrix]
25+
DATABRICKS_CLI_DEPLOYMENT = ["terraform"]

0 commit comments

Comments
 (0)