GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [improve][ci] Run the Python function instance tests in CI (#26399) · apache/pulsar@9890872

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • .github/workflows
    • ci-python-functions.yaml
  • pulsar-functions/instance/src/scripts
    • run_python_instance_tests.sh
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎.github/workflows/ci-python-functions.yaml‎

Copy file name to clipboard
+90Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#
2+
# Licensed to the Apache Software Foundation (ASF) under one
3+
# or more contributor license agreements. See the NOTICE file
4+
# distributed with this work for additional information
5+
# regarding copyright ownership. The ASF licenses this file
6+
# to you under the Apache License, Version 2.0 (the
7+
# "License"); you may not use this file except in compliance
8+
# with the License. You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing,
13+
# software distributed under the License is distributed on an
14+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
# KIND, either express or implied. See the License for the
16+
# specific language governing permissions and limitations
17+
# under the License.
18+
#
19+
20+
name: CI - Python Functions
21+
on:
22+
pull_request:
23+
branches:
24+
- master
25+
paths:
26+
- '.github/workflows/**'
27+
- 'pulsar-functions/instance/src/main/python/**'
28+
- 'pulsar-functions/instance/src/test/python/**'
29+
- 'pulsar-functions/instance/src/scripts/**'
30+
workflow_dispatch:
31+
32+
concurrency:
33+
group: ${{ github.workflow }}-${{ github.ref }}
34+
cancel-in-progress: true
35+
36+
jobs:
37+
preconditions:
38+
name: Preconditions
39+
runs-on: ubuntu-24.04
40+
outputs:
41+
docs_only: ${{ steps.check_changes.outputs.docs_only }}
42+
steps:
43+
- name: checkout
44+
uses: actions/checkout@v6
45+
46+
- name: Detect changed files
47+
id: changes
48+
uses: apache/pulsar-test-infra/paths-filter@master
49+
with:
50+
filters: .github/changes-filter.yaml
51+
list-files: csv
52+
53+
- name: Check changed files
54+
id: check_changes
55+
run: |
56+
if [[ "${GITHUB_EVENT_NAME}" != "schedule" ]]; then
57+
echo "docs_only=${{ fromJSON(steps.changes.outputs.all_count) == fromJSON(steps.changes.outputs.docs_count) && fromJSON(steps.changes.outputs.docs_count) > 0 }}" >> $GITHUB_OUTPUT
58+
else
59+
echo docs_only=false >> $GITHUB_OUTPUT
60+
fi
61+
62+
- name: Check if the PR is ready for running CI
63+
if: ${{ steps.check_changes.outputs.docs_only != 'true' && github.repository == 'apache/pulsar' && github.event_name == 'pull_request' }}
64+
uses: ./.github/actions/check-pr-ready-to-test
65+
66+
instance-tests:
67+
needs: preconditions
68+
if: ${{ needs.preconditions.outputs.docs_only != 'true' }}
69+
name: Python ${{ matrix.python-version }} Functions instance tests
70+
runs-on: ubuntu-24.04
71+
strategy:
72+
fail-fast: false
73+
matrix:
74+
python-version: ['3.12', '3.13']
75+
76+
steps:
77+
- name: checkout
78+
uses: actions/checkout@v6
79+
80+
- name: Tune Runner VM
81+
uses: ./.github/actions/tune-runner-vm
82+
83+
- name: Set up Python
84+
uses: actions/setup-python@v6
85+
with:
86+
python-version: ${{ matrix.python-version }}
87+
88+
- name: Run Python instance tests
89+
run: |
90+
./pulsar-functions/instance/src/scripts/run_python_instance_tests.sh
Collapse file

‎pulsar-functions/instance/src/scripts/run_python_instance_tests.sh‎

Copy file name to clipboardExpand all lines: pulsar-functions/instance/src/scripts/run_python_instance_tests.sh
+47-7Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,54 @@
1818
# under the License.
1919
#
2020

21-
22-
# Make sure dependencies are installed
23-
pip3 install mock --user
24-
pip3 install protobuf==6.31.1 --user
25-
pip3 install fastavro --user
21+
set -o errexit
22+
set -o nounset
23+
set -o pipefail
2624

2725
CUR_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
2826
PULSAR_HOME="$( cd "$CUR_DIR/../../../../" >/dev/null && pwd )"
2927

30-
# run instance tests
31-
PULSAR_HOME=${PULSAR_HOME} PYTHONPATH=${PULSAR_HOME}/pulsar-functions/instance/src/main/python python3 -m unittest discover -v -s ${PULSAR_HOME}/pulsar-functions/instance/src/test/python
28+
PYTHON_BIN=${PYTHON_BIN:-python3}
29+
30+
# Keep these aligned with the Python dependencies installed in docker/pulsar/Dockerfile: the tests
31+
# should run against the same versions the Python instance runs with in production. pulsar-client's
32+
# "all" extra brings in apache-bookkeeper-client, fastavro, prometheus_client and ratelimit, which
33+
# the instance imports.
34+
PULSAR_CLIENT_PYTHON_VERSION=${PULSAR_CLIENT_PYTHON_VERSION:-3.13.0}
35+
PYTHON_GRPCIO_VERSION=${PYTHON_GRPCIO_VERSION:-1.78.0}
36+
PYTHON_PROTOBUF_VERSION=${PYTHON_PROTOBUF_VERSION:-6.33.6}
37+
38+
# Set SKIP_PYTHON_DEPS=true to run against an environment you have prepared yourself. Otherwise the
39+
# dependencies are installed into whatever ${PYTHON_BIN} resolves to, so run this inside a
40+
# virtualenv unless you want them on your system interpreter.
41+
if [[ "${SKIP_PYTHON_DEPS:-false}" != "true" ]]; then
42+
${PYTHON_BIN} -m pip install \
43+
mock \
44+
"pulsar-client[all]==${PULSAR_CLIENT_PYTHON_VERSION}" \
45+
"grpcio==${PYTHON_GRPCIO_VERSION}" \
46+
"protobuf==${PYTHON_PROTOBUF_VERSION}"
47+
fi
48+
49+
TEST_DIR="${PULSAR_HOME}/pulsar-functions/instance/src/test/python"
50+
export PULSAR_HOME
51+
export PYTHONPATH="${PULSAR_HOME}/pulsar-functions/instance/src/main/python"
52+
53+
# Each test module runs in its own interpreter. They cannot share one: test_python_instance replaces
54+
# prometheus_client with a mock in sys.modules, which breaks test_python_instance_main when it later
55+
# imports the real one, and the two modules also register the same Prometheus metrics, so a shared
56+
# registry rejects the duplicates.
57+
failed_modules=()
58+
for test_file in "${TEST_DIR}"/test_*.py; do
59+
module_name="$(basename "${test_file}" .py)"
60+
echo "=== Running ${module_name} ==="
61+
if ! (cd "${TEST_DIR}" && ${PYTHON_BIN} -m unittest -v "${module_name}"); then
62+
failed_modules+=("${module_name}")
63+
fi
64+
done
65+
66+
if [[ ${#failed_modules[@]} -gt 0 ]]; then
67+
echo "Failed test modules: ${failed_modules[*]}" >&2
68+
exit 1
69+
fi
70+
71+
echo "All Python instance test modules passed"

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.