This is an automated email from the ASF dual-hosted git repository. hgruszecki pushed a commit to branch 1889-test-examples in repository https://gitbox.apache.org/repos/asf/iggy.git
commit 8ce703cdef0a35a19df496d515cc397bf8f62665 Author: Huan-Cheng Chang <[email protected]> AuthorDate: Sun Sep 14 22:20:00 2025 +0100 chore(example): test python examples in CI --- .../actions/python-maturin/pre-merge/action.yml | 13 +++++ examples/python/basic/consumer.py | 1 + examples/python/basic/producer.py | 1 + foreign/python/scripts/test_examples.sh | 60 ++++++++++++++++++++++ 4 files changed, 75 insertions(+) diff --git a/.github/actions/python-maturin/pre-merge/action.yml b/.github/actions/python-maturin/pre-merge/action.yml index 878845cc0..75eda5161 100644 --- a/.github/actions/python-maturin/pre-merge/action.yml +++ b/.github/actions/python-maturin/pre-merge/action.yml @@ -137,6 +137,19 @@ runs: exit ${TEST_EXIT_CODE:-0} shell: bash + - name: Run Python example tests + if: inputs.task == 'test' && steps.iggy.outcome == 'success' + run: | + echo "Running example tests with Iggy server at ${{ steps.iggy.outputs.address }}..." + + IGGY_SERVER_HOST=127.0.0.1 \ + IGGY_SERVER_TCP_PORT=8090 \ + ./foreign/python/scripts/test_examples.sh || TEST_EXIT_CODE=$? + + # Exit with test result + exit ${TEST_EXIT_CODE:-0} + shell: bash + - name: Run Python unit tests only (fallback) if: inputs.task == 'test' && steps.iggy.outcome != 'success' run: | diff --git a/examples/python/basic/consumer.py b/examples/python/basic/consumer.py index 8523bf8cf..8a4829feb 100644 --- a/examples/python/basic/consumer.py +++ b/examples/python/basic/consumer.py @@ -40,6 +40,7 @@ def parse_args() -> argparse.Namespace: "Connection string for Iggy client, e.g. 'iggy+tcp://iggy:[email protected]:8090'" ), default="iggy+tcp://iggy:[email protected]:8090", + nargs="?", type=str, ) return parser.parse_args() diff --git a/examples/python/basic/producer.py b/examples/python/basic/producer.py index b3548f70d..624074467 100644 --- a/examples/python/basic/producer.py +++ b/examples/python/basic/producer.py @@ -41,6 +41,7 @@ def parse_args() -> argparse.Namespace: "Connection string for Iggy client, e.g. 'iggy+tcp://iggy:[email protected]:8090'" ), default="iggy+tcp://iggy:[email protected]:8090", + nargs="?", type=str, ) return parser.parse_args() diff --git a/foreign/python/scripts/test_examples.sh b/foreign/python/scripts/test_examples.sh new file mode 100755 index 000000000..08dc77392 --- /dev/null +++ b/foreign/python/scripts/test_examples.sh @@ -0,0 +1,60 @@ +#!/bin/bash + +# Must be executed from the root of the repo. + +echo "🚀 Running example scripts..." + +cd examples/python || exit 1 + +EXEC_TIMEOUT_SEC=5 + +for example in ./*; do + # Skip readme + if [ -f "./$example" ]; then + continue + fi + + # Run producer + producer_path="./$example/producer.py" + if [ ! -f "$producer_path" ]; then + echo "⚠️ producer.py not found in example '${example}'" + TEST_EXIT_CODE=1 + continue + fi + + # Note: Examples might run indefinitely, so we'll just test they start correctly + # Assuming that the script does not require arguments or has default arguments + timeout $EXEC_TIMEOUT_SEC python3 "$producer_path" + EXIT_CODE=$? + + # Code 124: default exit code produced by timeout when the task runs out of time + if [[ $EXIT_CODE = 0 || $EXIT_CODE = 124 ]]; then + echo "✅ Producer in example '$example' started successfully" + else + echo "❌ Producer in example '$example' failed to start" + TEST_EXIT_CODE=1 + continue + fi + + # Run consumer + consumer_path="./$example/consumer.py" + if [ ! -f "$consumer_path" ]; then + echo "⚠️ consumer.py not found in example '$example'" + TEST_EXIT_CODE=1 + continue + fi + + # Note: Examples might run indefinitely, so we'll just test they start correctly + # Assuming that the script does not require arguments or has default arguments. + timeout $EXEC_TIMEOUT_SEC python3 "$consumer_path" + EXIT_CODE=$? + + if [[ $EXIT_CODE = 0 || $EXIT_CODE = 124 ]]; then + echo "✅ Consumer in example '$example' started successfully" + else + echo "❌ Consumer in example '$example' failed to start" + TEST_EXIT_CODE=1 + fi +done + +exit "$TEST_EXIT_CODE"
