Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 85 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ jobs:
run: |
twine check dist/*

test:
test-linux-container:
runs-on: ubuntu-latest
needs: build-check
strategy:
Expand Down Expand Up @@ -288,3 +288,87 @@ jobs:
with:
name: testgres--test_logs--${{ env.RUN_CFG__NOW }}-${{ env.BASE_SIGN }}-id${{ github.run_id }}
path: "${{ env.RUN_CFG__LOGS_DIR }}/"

test-macos-14:
runs-on: macos-14
needs: build-check
strategy:
fail-fast: false
matrix:
include:
- python: "3.9"
postgres: "17"
case_suffix: "py3_09_xx-pg17_xx"
- python: "3.10"
postgres: "17"
case_suffix: "py3_10_xx-pg17_xx"
- python: "3.11"
postgres: "17"
case_suffix: "py3_11_xx-pg17_xx"
- python: "3.12"
postgres: "17"
case_suffix: "py3_12_xx-pg17_xx"
- python: "3.13"
postgres: "17"
case_suffix: "py3_13_xx-pg17_xx"
- python: "3.14"
postgres: "17"
case_suffix: "py3_14_xx-pg17_xx"

name: "test: macos-14 | ${{ matrix.case_suffix }}"

env:
BASE_SIGN: "macos-py${{ matrix.python }}-pg${{ matrix.postgres }}"

steps:
- name: Prepare variables
run: |
echo "RUN_CFG__NOW=$(date +'%Y%m%d_%H%M%S')" >> $GITHUB_ENV
echo "RUN_CFG__LOGS_DIR=logs-${{ env.BASE_SIGN }}" >> $GITHUB_ENV
echo "---------- [$GITHUB_ENV]"
cat $GITHUB_ENV

- name: Checkout
uses: actions/checkout@v7

- name: Prepare logs folder on the host
run: mkdir -p "${{ env.RUN_CFG__LOGS_DIR }}"

- name: Set up Python ${{ matrix.python }}
uses: actions/setup-python@v7
with:
python-version: ${{ matrix.python }}
cache: 'pip'

- name: Install PostgreSQL ${{ matrix.postgres }} via Homebrew
run: |
brew update
# Install the specified version of the DBMS
brew install postgresql@${{ matrix.postgres }}

# Add postgres binaries (pg_ctl, initdb, etc.) to GITHUB_PATH,
# so that they are globally available for testing (Homebrew does not automatically link older/specific versions)
echo "$(brew --prefix postgresql@${{ matrix.postgres }})/bin" >> $GITHUB_PATH

- name: Run native tests (Local operations only)
run: |
set -eux
echo "HELLO FROM MACOS RUNNER"
echo "HOME DIR IS [$(realpath ~/)]"
echo "WORK DIR IS [$(pwd)]"

postgres --version

export TEST_CFG__LOG_DIR="${{ github.workspace }}/${{ env.RUN_CFG__LOGS_DIR }}"

export TEST_FILTER="not remote"
export PYTHON_BINARY="python3"

bash run_tests-darwin.sh

- name: Upload Logs
uses: actions/upload-artifact@v7
if: always() # IT IS IMPORTANT!
with:
name: testgres--test_logs--${{ env.RUN_CFG__NOW }}-${{ env.BASE_SIGN }}-id${{ github.run_id }}
path: "${{ env.RUN_CFG__LOGS_DIR }}/"
134 changes: 134 additions & 0 deletions run_tests-darwin.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
#!/usr/bin/env bash

set -eux

# Filter tests for local execution (without remote/ssh)
if [ -z ${TEST_FILTER+x} ]; then
export TEST_FILTER="TestTestgresLocal or (TestTestgresCommon and (not remote))"
fi

# There is no nproc on macOS, so we use sysctl
echo NPROC: $(sysctl -n hw.ncpu)

# Check for the presence of pg_config
echo check that pg_config is in PATH
command -v pg_config

# Setting up the Python environment
VENV_PATH="/tmp/testgres_venv"
rm -rf $VENV_PATH
${PYTHON_BINARY} -m venv "${VENV_PATH}"
export VIRTUAL_ENV_DISABLE_PROMPT=1
source "${VENV_PATH}/bin/activate"
pip install --upgrade pip setuptools wheel
pip install -r tests/requirements.txt

# remove existing coverage file
export COVERAGE_FILE=.coverage
rm -f $COVERAGE_FILE

pip install coverage

exec_command() {
local cmd="$1"
local prefix="$2"

eval "$prefix $cmd"
}

show_fs_state__impl() {
local prefix="$1"
local host_label="$2"

set +x
echo "------------- ${host_label} FS STATE"
set -x
# Change for macOS: use the cross-platform -P flag instead of -T
exec_command "df -P" "$prefix"
}

check_leftover_ports__impl() {
local prefix="$1"
local host_label="$2"
local ports_dir="/tmp/testgres/ports"

set +x
echo "------------- Checking ${host_label} ports lock directory"
set -x

# Check command: will print FOUND if the directory exists and is not empty
local check_cmd="if [ -d '${ports_dir}' ] && [ \"\$(ls -A '${ports_dir}' 2>/dev/null)\" ]; then echo 'FOUND'; fi"

# Temporarily disable bash's instant drop (set +e) to safely intercept the result
set +e
local result
result=$(exec_command "$check_cmd" "$prefix")
set -e

set +x
if [ "$result" = "FOUND" ]; then
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
echo "ERROR: Leftover ports detected in $ports_dir on $host_label machine!"
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
set -x

# We display a list of frozen ports so that the culprits can be identified
exec_command "ls -la '$ports_dir'" "$prefix"

# We hard-drop the entire control script
# sleep 3600
exit 1
else
echo "Clear. No leftover port locks."
fi
set -x
}

fs_verification() {
show_fs_state__impl "" "LOCAL"

check_leftover_ports__impl "" "LOCAL"
}

# ---------------------------------------- PATH

fs_verification

# run tests (PATH)
time coverage run -a -m pytest -l -vvv -n auto --color=yes -k "${TEST_FILTER}"

# ---------------------------------------- PG_BIN

fs_verification

# run tests (PG_BIN)
PG_BIN=$(pg_config --bindir) \
time coverage run -a -m pytest -l -vvv -n auto --color=yes -k "${TEST_FILTER}"

# ---------------------------------------- PG_CONFIG

fs_verification

# run tests (PG_CONFIG)
PG_CONFIG=$(pg_config --bindir)/pg_config \
time coverage run -a -m pytest -l -vvv -n auto --color=yes -k "${TEST_FILTER}"

# ---------------------------------------- pg8000

fs_verification

# test pg8000
pip uninstall -y psycopg2
pip install pg8000
PG_CONFIG=$(pg_config --bindir)/pg_config \
time coverage run -a -m pytest -l -vvv -n auto --color=yes -k "${TEST_FILTER}"

# ---------------------------------------- finish

fs_verification

# ---------------------------------------- coverage

coverage report

pip uninstall -y coverage
Loading
Loading