Skip to content

Commit 32d578d

Browse files
Workflow to test app + script to test workflow
1 parent 22f075e commit 32d578d

5 files changed

Lines changed: 140 additions & 0 deletions

File tree

.github/workflows/build_docker.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: build_docker
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
version:
7+
description: 'Image version (e.g. 1.0.0)'
8+
required: true
9+
type: string
10+
11+
jobs:
12+
build:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v4
16+
17+
- name: Build Docker image
18+
run: docker build -t pool-simulator:${{ inputs.version }} .
19+
20+
- name: Save image as tar
21+
run: docker save pool-simulator:${{ inputs.version }} -o pool-simulator-${{ inputs.version }}.tar
22+
23+
- name: Upload artifact
24+
uses: actions/upload-artifact@v4
25+
with:
26+
name: pool-simulator-${{ inputs.version }}
27+
path: pool-simulator-${{ inputs.version }}.tar

.github/workflows/test_install.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: test_install
2+
3+
on:
4+
push:
5+
branches: [main]
6+
7+
jobs:
8+
install:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v4
12+
13+
- uses: actions/setup-python@v5
14+
with:
15+
python-version: '3.11'
16+
17+
- name: Install requirements
18+
run: pip install -r requirements.txt
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: test_workflow
2+
3+
on:
4+
push:
5+
branches: [main]
6+
7+
jobs:
8+
workflow:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v4
12+
13+
- uses: actions/setup-python@v5
14+
with:
15+
python-version: '3.11'
16+
17+
- name: Install requirements
18+
run: pip install -r requirements.txt
19+
20+
- name: Start stratum workflow server
21+
run: |
22+
python main.py \
23+
--algo workflow \
24+
--workflow-file workflow.example.json \
25+
--workflow-name workflow_sample_1 \
26+
--port 7878 &
27+
28+
- name: Run workflow client test
29+
run: python scripts/test_workflow_client.py

Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
FROM python:3.11-slim
2+
WORKDIR /app
3+
COPY requirements.txt .
4+
RUN pip install --no-cache-dir -r requirements.txt
5+
COPY . .
6+
ENTRYPOINT ["python", "main.py"]

scripts/test_workflow_client.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import json
2+
import socket
3+
import sys
4+
import time
5+
6+
HOST = '127.0.0.1'
7+
PORT = 7878
8+
EXPECTED_STEPS = 3
9+
TIMEOUT = 10
10+
11+
12+
def wait_for_server(timeout: int) -> None:
13+
deadline = time.monotonic() + timeout
14+
while time.monotonic() < deadline:
15+
try:
16+
s = socket.create_connection((HOST, PORT), timeout=1)
17+
s.close()
18+
return
19+
except OSError:
20+
time.sleep(0.2)
21+
print(f'Server did not open on {HOST}:{PORT} within {timeout}s', file=sys.stderr)
22+
sys.exit(1)
23+
24+
25+
def run() -> None:
26+
wait_for_server(TIMEOUT)
27+
28+
sock = socket.create_connection((HOST, PORT), timeout=TIMEOUT)
29+
steps_done = 0
30+
buf = ''
31+
32+
try:
33+
while steps_done < EXPECTED_STEPS:
34+
chunk = sock.recv(4096).decode()
35+
if not chunk:
36+
print('Connection closed unexpectedly', file=sys.stderr)
37+
sys.exit(1)
38+
buf += chunk
39+
lines = buf.split('\n')
40+
buf = lines[-1]
41+
for line in lines[:-1]:
42+
line = line.strip()
43+
if not line:
44+
continue
45+
msg = json.loads(line)
46+
msg_id = msg.get('id')
47+
if msg_id is None:
48+
continue
49+
response = json.dumps({'id': msg_id, 'result': True}) + '\n'
50+
sock.sendall(response.encode())
51+
steps_done += 1
52+
print(f'step {steps_done}/{EXPECTED_STEPS} ok (id={msg_id})')
53+
finally:
54+
sock.close()
55+
56+
print(f'{steps_done} steps completed successfully')
57+
58+
59+
if __name__ == '__main__':
60+
run()

0 commit comments

Comments
 (0)