Skip to content

Commit 7ef8d38

Browse files
whummerclaude
andcommitted
add CI workflow for utils package tests
- Add .github/workflows/utils.yml with unit and integration test jobs - Use localstack.utils.net.wait_for_port_open instead of custom implementation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 75f2301 commit 7ef8d38

File tree

2 files changed

+73
-21
lines changed

2 files changed

+73
-21
lines changed

.github/workflows/utils.yml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: LocalStack Extensions Utils Tests
2+
3+
on:
4+
push:
5+
paths:
6+
- utils/**
7+
branches:
8+
- main
9+
pull_request:
10+
paths:
11+
- .github/workflows/utils.yml
12+
- utils/**
13+
workflow_dispatch:
14+
15+
jobs:
16+
unit-tests:
17+
name: Run Unit Tests
18+
runs-on: ubuntu-latest
19+
timeout-minutes: 5
20+
steps:
21+
- name: Checkout
22+
uses: actions/checkout@v4
23+
24+
- name: Set up Python
25+
uses: actions/setup-python@v5
26+
with:
27+
python-version: "3.11"
28+
29+
- name: Install dependencies
30+
run: |
31+
cd utils
32+
pip install -e .[dev,test]
33+
34+
- name: Lint
35+
run: |
36+
cd utils
37+
make lint
38+
39+
- name: Run unit tests
40+
run: |
41+
cd utils
42+
make test-unit
43+
44+
integration-tests:
45+
name: Run Integration Tests
46+
runs-on: ubuntu-latest
47+
timeout-minutes: 10
48+
steps:
49+
- name: Checkout
50+
uses: actions/checkout@v4
51+
52+
- name: Set up Python
53+
uses: actions/setup-python@v5
54+
with:
55+
python-version: "3.11"
56+
57+
- name: Install dependencies
58+
run: |
59+
cd utils
60+
pip install -e .[dev,test]
61+
62+
- name: Pull grpcbin image
63+
run: docker pull moul/grpcbin
64+
65+
- name: Run integration tests
66+
run: |
67+
cd utils
68+
make test-integration

utils/tests/integration/conftest.py

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,34 +7,16 @@
77

88
import subprocess
99
import time
10-
import socket
1110
import pytest
1211

12+
from localstack.utils.net import wait_for_port_open
13+
1314

1415
GRPCBIN_IMAGE = "moul/grpcbin"
1516
GRPCBIN_INSECURE_PORT = 9000 # HTTP/2 without TLS
1617
GRPCBIN_SECURE_PORT = 9001 # HTTP/2 with TLS
1718

1819

19-
def is_port_open(host: str, port: int, timeout: float = 1.0) -> bool:
20-
"""Check if a port is open and accepting connections."""
21-
try:
22-
with socket.create_connection((host, port), timeout=timeout):
23-
return True
24-
except (socket.timeout, socket.error, ConnectionRefusedError, OSError):
25-
return False
26-
27-
28-
def wait_for_port(host: str, port: int, timeout: float = 30.0) -> bool:
29-
"""Wait for a port to become available."""
30-
start_time = time.time()
31-
while time.time() - start_time < timeout:
32-
if is_port_open(host, port):
33-
return True
34-
time.sleep(0.5)
35-
return False
36-
37-
3820
@pytest.fixture(scope="session")
3921
def grpcbin_container():
4022
"""
@@ -92,7 +74,9 @@ def grpcbin_container():
9274
container_id = result.stdout.strip()
9375

9476
# Wait for the insecure port to be ready
95-
if not wait_for_port("localhost", GRPCBIN_INSECURE_PORT, timeout=30):
77+
try:
78+
wait_for_port_open(GRPCBIN_INSECURE_PORT, retries=60, sleep_time=0.5)
79+
except Exception:
9680
# Clean up and fail
9781
subprocess.run(["docker", "rm", "-f", container_name], capture_output=True)
9882
pytest.fail(f"grpcbin port {GRPCBIN_INSECURE_PORT} did not become available")

0 commit comments

Comments
 (0)