Skip to content

Commit f50e8dc

Browse files
A formal support of macos is added (#435)
* darwin: os_ops tests are updated * linux: internal_platform_utils.py is corrected 1) ProcessIsZombi_soft_check is corrected (raise) 2) Bad assert in _find_postmaster__throw_error__bad_line_format * darwin/internal_platform_utils.py is added * CI: test-macos-14 is added * run_tests-darwin: pytest --color=yes * run_tests-darwin: pytest -n auto * fix: NodeApp::_gettempdir is corrected * run_tests-darwin: pytest --color=yes (v2) * macos: TEST_FILTER="not remote" * darwin: internal_platform_utils is updated (sync with linux) * CI: run of "test-linux-container" is restored * linux::InternalPlatformUtils::ProcessIsZombi_soft_check is restored * darwin::InternalPlatformUtils::ProcessIsZombi_soft_check is corrected * CI: English * darwin::internal_platform_utils is rewritten _FindPostmaster - uses "-ewwo" (as in linux version) ProcessIsZombi_soft_check - new exact code, "-wwo" is used * CI: (macos-14) matrix is rebuilt
1 parent 1348869 commit f50e8dc

6 files changed

Lines changed: 742 additions & 8 deletions

File tree

.github/workflows/ci.yml

Lines changed: 85 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ jobs:
6767
run: |
6868
twine check dist/*
6969
70-
test:
70+
test-linux-container:
7171
runs-on: ubuntu-latest
7272
needs: build-check
7373
strategy:
@@ -288,3 +288,87 @@ jobs:
288288
with:
289289
name: testgres--test_logs--${{ env.RUN_CFG__NOW }}-${{ env.BASE_SIGN }}-id${{ github.run_id }}
290290
path: "${{ env.RUN_CFG__LOGS_DIR }}/"
291+
292+
test-macos-14:
293+
runs-on: macos-14
294+
needs: build-check
295+
strategy:
296+
fail-fast: false
297+
matrix:
298+
include:
299+
- python: "3.9"
300+
postgres: "17"
301+
case_suffix: "py3_09_xx-pg17_xx"
302+
- python: "3.10"
303+
postgres: "17"
304+
case_suffix: "py3_10_xx-pg17_xx"
305+
- python: "3.11"
306+
postgres: "17"
307+
case_suffix: "py3_11_xx-pg17_xx"
308+
- python: "3.12"
309+
postgres: "17"
310+
case_suffix: "py3_12_xx-pg17_xx"
311+
- python: "3.13"
312+
postgres: "17"
313+
case_suffix: "py3_13_xx-pg17_xx"
314+
- python: "3.14"
315+
postgres: "17"
316+
case_suffix: "py3_14_xx-pg17_xx"
317+
318+
name: "test: macos-14 | ${{ matrix.case_suffix }}"
319+
320+
env:
321+
BASE_SIGN: "macos-py${{ matrix.python }}-pg${{ matrix.postgres }}"
322+
323+
steps:
324+
- name: Prepare variables
325+
run: |
326+
echo "RUN_CFG__NOW=$(date +'%Y%m%d_%H%M%S')" >> $GITHUB_ENV
327+
echo "RUN_CFG__LOGS_DIR=logs-${{ env.BASE_SIGN }}" >> $GITHUB_ENV
328+
echo "---------- [$GITHUB_ENV]"
329+
cat $GITHUB_ENV
330+
331+
- name: Checkout
332+
uses: actions/checkout@v7
333+
334+
- name: Prepare logs folder on the host
335+
run: mkdir -p "${{ env.RUN_CFG__LOGS_DIR }}"
336+
337+
- name: Set up Python ${{ matrix.python }}
338+
uses: actions/setup-python@v7
339+
with:
340+
python-version: ${{ matrix.python }}
341+
cache: 'pip'
342+
343+
- name: Install PostgreSQL ${{ matrix.postgres }} via Homebrew
344+
run: |
345+
brew update
346+
# Install the specified version of the DBMS
347+
brew install postgresql@${{ matrix.postgres }}
348+
349+
# Add postgres binaries (pg_ctl, initdb, etc.) to GITHUB_PATH,
350+
# so that they are globally available for testing (Homebrew does not automatically link older/specific versions)
351+
echo "$(brew --prefix postgresql@${{ matrix.postgres }})/bin" >> $GITHUB_PATH
352+
353+
- name: Run native tests (Local operations only)
354+
run: |
355+
set -eux
356+
echo "HELLO FROM MACOS RUNNER"
357+
echo "HOME DIR IS [$(realpath ~/)]"
358+
echo "WORK DIR IS [$(pwd)]"
359+
360+
postgres --version
361+
362+
export TEST_CFG__LOG_DIR="${{ github.workspace }}/${{ env.RUN_CFG__LOGS_DIR }}"
363+
364+
export TEST_FILTER="not remote"
365+
export PYTHON_BINARY="python3"
366+
367+
bash run_tests-darwin.sh
368+
369+
- name: Upload Logs
370+
uses: actions/upload-artifact@v7
371+
if: always() # IT IS IMPORTANT!
372+
with:
373+
name: testgres--test_logs--${{ env.RUN_CFG__NOW }}-${{ env.BASE_SIGN }}-id${{ github.run_id }}
374+
path: "${{ env.RUN_CFG__LOGS_DIR }}/"

run_tests-darwin.sh

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
#!/usr/bin/env bash
2+
3+
set -eux
4+
5+
# Filter tests for local execution (without remote/ssh)
6+
if [ -z ${TEST_FILTER+x} ]; then
7+
export TEST_FILTER="TestTestgresLocal or (TestTestgresCommon and (not remote))"
8+
fi
9+
10+
# There is no nproc on macOS, so we use sysctl
11+
echo NPROC: $(sysctl -n hw.ncpu)
12+
13+
# Check for the presence of pg_config
14+
echo check that pg_config is in PATH
15+
command -v pg_config
16+
17+
# Setting up the Python environment
18+
VENV_PATH="/tmp/testgres_venv"
19+
rm -rf $VENV_PATH
20+
${PYTHON_BINARY} -m venv "${VENV_PATH}"
21+
export VIRTUAL_ENV_DISABLE_PROMPT=1
22+
source "${VENV_PATH}/bin/activate"
23+
pip install --upgrade pip setuptools wheel
24+
pip install -r tests/requirements.txt
25+
26+
# remove existing coverage file
27+
export COVERAGE_FILE=.coverage
28+
rm -f $COVERAGE_FILE
29+
30+
pip install coverage
31+
32+
exec_command() {
33+
local cmd="$1"
34+
local prefix="$2"
35+
36+
eval "$prefix $cmd"
37+
}
38+
39+
show_fs_state__impl() {
40+
local prefix="$1"
41+
local host_label="$2"
42+
43+
set +x
44+
echo "------------- ${host_label} FS STATE"
45+
set -x
46+
# Change for macOS: use the cross-platform -P flag instead of -T
47+
exec_command "df -P" "$prefix"
48+
}
49+
50+
check_leftover_ports__impl() {
51+
local prefix="$1"
52+
local host_label="$2"
53+
local ports_dir="/tmp/testgres/ports"
54+
55+
set +x
56+
echo "------------- Checking ${host_label} ports lock directory"
57+
set -x
58+
59+
# Check command: will print FOUND if the directory exists and is not empty
60+
local check_cmd="if [ -d '${ports_dir}' ] && [ \"\$(ls -A '${ports_dir}' 2>/dev/null)\" ]; then echo 'FOUND'; fi"
61+
62+
# Temporarily disable bash's instant drop (set +e) to safely intercept the result
63+
set +e
64+
local result
65+
result=$(exec_command "$check_cmd" "$prefix")
66+
set -e
67+
68+
set +x
69+
if [ "$result" = "FOUND" ]; then
70+
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
71+
echo "ERROR: Leftover ports detected in $ports_dir on $host_label machine!"
72+
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
73+
set -x
74+
75+
# We display a list of frozen ports so that the culprits can be identified
76+
exec_command "ls -la '$ports_dir'" "$prefix"
77+
78+
# We hard-drop the entire control script
79+
# sleep 3600
80+
exit 1
81+
else
82+
echo "Clear. No leftover port locks."
83+
fi
84+
set -x
85+
}
86+
87+
fs_verification() {
88+
show_fs_state__impl "" "LOCAL"
89+
90+
check_leftover_ports__impl "" "LOCAL"
91+
}
92+
93+
# ---------------------------------------- PATH
94+
95+
fs_verification
96+
97+
# run tests (PATH)
98+
time coverage run -a -m pytest -l -vvv -n auto --color=yes -k "${TEST_FILTER}"
99+
100+
# ---------------------------------------- PG_BIN
101+
102+
fs_verification
103+
104+
# run tests (PG_BIN)
105+
PG_BIN=$(pg_config --bindir) \
106+
time coverage run -a -m pytest -l -vvv -n auto --color=yes -k "${TEST_FILTER}"
107+
108+
# ---------------------------------------- PG_CONFIG
109+
110+
fs_verification
111+
112+
# run tests (PG_CONFIG)
113+
PG_CONFIG=$(pg_config --bindir)/pg_config \
114+
time coverage run -a -m pytest -l -vvv -n auto --color=yes -k "${TEST_FILTER}"
115+
116+
# ---------------------------------------- pg8000
117+
118+
fs_verification
119+
120+
# test pg8000
121+
pip uninstall -y psycopg2
122+
pip install pg8000
123+
PG_CONFIG=$(pg_config --bindir)/pg_config \
124+
time coverage run -a -m pytest -l -vvv -n auto --color=yes -k "${TEST_FILTER}"
125+
126+
# ---------------------------------------- finish
127+
128+
fs_verification
129+
130+
# ---------------------------------------- coverage
131+
132+
coverage report
133+
134+
pip uninstall -y coverage

0 commit comments

Comments
 (0)