Skip to content

Commit 6370cf1

Browse files
committed
Refactor wheel tests and make them easier to run
1 parent 61a7074 commit 6370cf1

File tree

6 files changed

+224
-71
lines changed

6 files changed

+224
-71
lines changed

.travis.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ jobs:
4545
# Install cibuildwheel if this is a tagged PR
4646
before_install:
4747
- if [[ $TRAVIS_OS_NAME == "osx" ]]; then tools/prepare-osx.sh ${INTERPRETER_VERSION} /tmp/venv && source /tmp/venv/bin/activate; fi
48-
- if [[ -n $TRAVIS_TAG && -n $CIBW_BEFORE_BUILD ]]; then pip install -U -r tools/requirements-manylinux.txt --force-reinstall ; which wheel ; wheel version ; wheel -h ; fi
48+
- if [[ -n $TRAVIS_TAG && -n $CIBW_BEFORE_BUILD ]]; then pip install -U -r tools/requirements-manylinux.txt --force-reinstall ; fi
4949

5050
# Install interceptors
5151
# Install librdkafka if not CIBW_BEFORE_BUILD
@@ -69,8 +69,7 @@ after_script:
6969
- ldd staging/libs/* || otool -L staging/libs/* || true
7070
- if [[ -z $CIBW_BEFORE_BUILD && $TRAVIS_OS_NAME == "osx" ]]; then DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:staging/libs py.test --timeout=60 --ignore=tmp-build --import-mode append; fi
7171
- if [[ -z $CIBW_BEFORE_BUILD && $TRAVIS_OS_NAME == "linux" ]]; then LD_LIBRARY_PATH=$LD_LIBRARY_PATH:staging/libs py.test --timeout=60 --ignore=tmp-build --import-mode append; fi
72-
- if [[ -n $TRAVIS_TAG && $TRAVIS_OS_NAME == linux && -n $CIBW_BEFORE_BUILD ]];then tools/test-manylinux.sh; fi
73-
- if [[ -n $TRAVIS_TAG && $TRAVIS_OS_NAME == osx && -n $CIBW_BEFORE_BUILD ]]; then tools/test-osx.sh; fi
72+
- if [[ -n $TRAVIS_TAG && $TRAVIS_OS_NAME == osx && -n $CIBW_BEFORE_BUILD ]]; then tools/test-wheel.sh wheelhouse; fi
7473
- if [[ $MK_DOCS == y ]]; then make docs; fi
7574

7675
deploy:

tools/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,13 @@ This example only builds for Python 2.7 x64:
3232
$ CIBW_SKIP="cp3* cp*i686*" tools/cibuildwheel-build.sh wheelhouse
3333

3434
Packages will now be available in wheelhouse/
35+
36+
37+
38+
## How to test wheels
39+
40+
After wheels have been downloaded with `download-s3.py`, perform smoketests
41+
by running `tools/test-wheels.sh <download-dir>`, e.g.,
42+
`tools/test-wheels.sh tools/dl-v1.5.0rc1`.
43+
This script preferably be run on OSX (with Docker installed) so that
44+
both OSX and Linux wheels are tested.

tools/RELEASE.md

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -136,25 +136,10 @@ artifacts from S3 using:
136136

137137
The artifacts will be downloaded to `dl-<tag>/`.
138138

139-
140139
## 8. Verify packages
141140

142-
Create a new virtualenv:
143-
144-
$ rm -rf mytestenv2
145-
$ virtualenv mytestenv2
146-
$ source mytestenv2/bin/activate
147-
148-
Install the relevant package for your platform:
141+
$ tools/test-wheels.sh tools/dl-v0.11.4rc1
149142

150-
$ pip install --no-cache-dir --find-links dl-v0.11.4rc1/ confluent-kafka
151-
152-
Verify that the package works, should print the expected Python client
153-
and librdkafka versions:
154-
155-
$ python -c 'import confluent_kafka as ck ; print "py: {} c: {}" \
156-
.format(ck.version(), ck.libversion())'
157-
py: ('0.11.4', 721920) c: ('0.11.4-RC1', 722121)
158143

159144
## 10. Open a release PR
160145

tools/smoketest.sh

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
#!/bin/bash
2+
#
3+
4+
#
5+
# Run smoke tests to verify a vanilla installation of confluent-kafka.
6+
#
7+
# If a wheeldir is supplied confluent-kafka is first installed.
8+
#
9+
# Must be run from the top-level project directory.
10+
#
11+
12+
if [[ ! -f tools/$(basename $0) ]]; then
13+
echo "$0: Must be run from the top-level project directory"
14+
exit 1
15+
fi
16+
17+
set -e
18+
19+
wheeldir=$1
20+
testdir=
21+
22+
23+
if [[ -n $wheeldir ]]; then
24+
if [[ ! -d $wheeldir ]]; then
25+
echo "$0: wheeldir $wheeldir does not exist"
26+
exit 1
27+
fi
28+
python -m pip install virtualenv
29+
fi
30+
31+
32+
# Run tests with both python2 and python3 (whatever versions the OS provides)
33+
for py in 2.7 3.8 3.7 3.6 3.5 ; do
34+
echo "# Smoketest with Python$py"
35+
36+
if ! python$py -V ; then
37+
echo "$0: python$py not available: skipping"
38+
continue
39+
fi
40+
41+
if [[ -n $wheeldir ]]; then
42+
venvdir=$(mktemp -d /tmp/_venvXXXXXX)
43+
44+
function cleanup () {
45+
set +e
46+
deactivate
47+
echo $venvdir
48+
rm -rf "$venvdir"
49+
[[ -d $testdir ]] && rm -rf "$testdir"
50+
set -e
51+
}
52+
53+
trap cleanup EXIT
54+
55+
virtualenv -p python$py $venvdir
56+
source $venvdir/bin/activate
57+
hash -r
58+
59+
pip install -U pip pkginfo
60+
pip install -r tests/requirements.txt
61+
62+
# Get the packages version so we can pin the install
63+
# command to this version (which hopefully loads it from the wheeldir
64+
# rather than PyPi) while still allowing dependencies to be installed
65+
# from PyPi.
66+
# Assuming that the wheeldirectory only contains wheels for a single
67+
# version we can pick any wheel file.
68+
version=$(pkginfo -f version $(ls $wheeldir/confluent_kafka*.whl | head -1) | sed -e 's/^version: //')
69+
if [[ -z $version ]]; then
70+
echo "Unable to parse version from wheel files in $wheeldir"
71+
exit 1
72+
fi
73+
74+
pip install --find-links "$wheeldir" confluent-kafka==$version
75+
pip install --find-links "$wheeldir" confluent-kafka[avro]==$version
76+
pip install --find-links "$wheeldir" confluent-kafka[protobuf]==$version
77+
pip install --find-links "$wheeldir" confluent-kafka[json]==$version
78+
fi
79+
80+
81+
# Copy unit tests to temporary directory to avoid any conflicting __pycache__
82+
# directories from the source tree.
83+
testdir=$(mktemp -d /tmp/_testdirXXXXXX)
84+
cp tests/*.py $testdir/
85+
86+
# Change to a neutral path where there is no confluent_kafka sub-directory
87+
# that might interfere with module load.
88+
pushd $testdir
89+
echo "Running unit tests"
90+
pytest
91+
92+
fails=""
93+
94+
echo "Verifying OpenSSL"
95+
python -c "
96+
import confluent_kafka
97+
confluent_kafka.Producer({'ssl.cipher.suites':'DEFAULT'})
98+
" || fails="$fails OpenSSL"
99+
100+
for compr in gzip lz4 snappy zstd; do
101+
echo "Verifying $compr"
102+
python -c "
103+
import confluent_kafka
104+
confluent_kafka.Producer({'compression.codec':'$compr'})
105+
" || fails="$fails $compr"
106+
done
107+
108+
echo "Verifying Interceptor installation"
109+
echo "Note: Requires protobuf-c to be installed on the system."
110+
python -c '
111+
from confluent_kafka import Consumer
112+
113+
c = Consumer({"group.id": "test-linux", "plugin.library.paths": "monitoring-interceptor"})
114+
' || echo "Warning: interceptor test failed, which we ignore"
115+
116+
popd # $testdir
117+
done
118+
119+
if [[ -z $fails ]]; then
120+
echo "ALL SMOKE TESTS PASSED"
121+
exit 0
122+
fi
123+
124+
echo "SMOKE TEST FAILURES: $fails"
125+
exit 1
126+
127+

tools/test-manylinux.sh

Lines changed: 38 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -7,95 +7,80 @@
77
# Usage outside of docker:
88
# $ tools/test-manylinux.sh
99

10-
set -ex
10+
set -e
1111

12-
echo "$0 running from $(pwd)"
13-
14-
if [[ ! -z $1 ]]; then
15-
WHEELHOUSE=$1
12+
if [[ $1 == "--in-docker" ]]; then
13+
IN_DOCKER=1
14+
shift
1615
else
17-
WHEELHOUSE="wheelhouse"
16+
IN_DOCKER=0
17+
fi
18+
19+
if [[ -z $1 ]]; then
20+
echo "Usage: $0 <wheel-directory>"
21+
exit 1
1822
fi
1923

24+
WHEELHOUSE="$1"
25+
26+
if [[ ! -d $WHEELHOUSE ]]; then
27+
echo "Wheelhouse directory $WHEELHOUSE does not exist"
28+
exit 1
29+
fi
30+
31+
echo "$0 running from $(pwd)"
2032

2133

2234
function setup_centos {
2335
# CentOS container setup
24-
yum install -q -y python epel-release
25-
yum install -q -y python-pip
36+
yum install -q -y python python3 epel-release curl
2637
}
2738

2839
function setup_ubuntu {
2940
# Ubuntu container setup
3041
apt-get update
31-
apt-get install -y python python-pip
42+
apt-get install -y python python3 curl
3243
}
3344

3445

3546
function run_single_in_docker {
3647
# Run single test inside docker container
37-
local wheelhouse=/io/$1
48+
local wheelhouse=$1
49+
local testscript=$2
3850

3951
if [[ ! -d $wheelhouse ]]; then
4052
echo "On docker instance: wheelhouse $wheelhouse does not exist"
4153
exit 1
4254
fi
4355

4456
# Detect OS
45-
if grep -qi centos /etc/system-release /etc/redhat-release ; then
57+
if grep -qi centos /etc/system-release /etc/redhat-release 2>/dev/null ; then
4658
setup_centos
47-
elif grep -qiE 'ubuntu|debian' /etc/os-release ; then
59+
elif grep -qiE 'ubuntu|debian' /etc/os-release 2>/dev/null ; then
4860
setup_ubuntu
4961
else
5062
echo "WARNING: Don't know what platform I'm on: $(uname -a)"
5163
fi
5264

53-
# Make sure pip itself is up to date
54-
pip install -U pip
55-
hash -r # let go of previous 'pip'
56-
57-
# Install modules
58-
59-
# TODO: revisit to avoid hardcoding dependencies
60-
pip install "futures;python_version=='2.7'"
61-
pip install "enum34;python_version=='2.7'"
62-
pip install requests avro
63-
64-
pip install confluent_kafka --no-index -f $wheelhouse
65-
66-
# Pytest relies on a new version of six; later versions of pip fail to remove older versions gracefully
67-
# https://github.com/pypa/pip/issues/5247
68-
pip install pytest --ignore-installed six
69-
70-
echo "Verifying OpenSSL and zlib are properly linked"
71-
python -c '
72-
import confluent_kafka
73-
74-
p = confluent_kafka.Producer({"ssl.cipher.suites":"DEFAULT",
75-
"compression.codec":"gzip"})
76-
'
77-
78-
echo "Verifying Interceptor installation"
79-
python -c '
80-
from confluent_kafka import Consumer
81-
82-
c = Consumer({"group.id": "test-linux", "plugin.library.paths": "monitoring-interceptor"})
83-
'
84-
85-
pushd /io/tests
86-
# Remove cached files from previous runs
87-
rm -rf __pycache__ *.pyc
88-
# Test
89-
pytest --import-mode=append --ignore=avro
90-
popd
65+
# Don't install pip from distro packaging since it pulls
66+
# in a plethora of possibly outdated Python requirements that
67+
# might interfere with the newer packages from PyPi, such as six.
68+
# Instead install it directly from PyPa.
69+
curl https://bootstrap.pypa.io/get-pip.py | python
9170

71+
/io/tools/smoketest.sh "$wheelhouse"
9272
}
9373

9474
function run_all_with_docker {
9575
# Run tests in all listed docker containers.
9676
# This is executed on the host.
9777
local wheelhouse=$1
9878

79+
if [[ ! -d ./$wheelhouse ]]; then
80+
echo "$wheelhouse must be a relative subdirectory of $(pwd)"
81+
exit 1
82+
fi
83+
9984
[[ ! -z $DOCKER_IMAGES ]] || \
10085
# LTS and stable release of popular Linux distros.
10186
# We require >= Python 2.7 to be avaialble (which rules out Centos 6.6)
@@ -113,16 +98,17 @@ function run_all_with_docker {
11398

11499
for DOCKER_IMAGE in $DOCKER_IMAGES; do
115100
echo "# Testing on $DOCKER_IMAGE"
116-
docker run -v $(pwd):/io $DOCKER_IMAGE /io/tools/test-manylinux.sh "$wheelhouse" || \
101+
docker run -v $(pwd):/io $DOCKER_IMAGE /io/tools/test-manylinux.sh --in-docker "/io/$wheelhouse" || \
117102
(echo "Failed on $DOCKER_IMAGE" ; false)
118103

119104
done
120105
}
121106

122107

123108

124-
if [[ -f /.dockerenv && -d /io ]]; then
109+
if [[ $IN_DOCKER == 1 ]]; then
125110
# Called from within a docker container
111+
cd /io # Enter the confluent-kafka-python top level directory
126112
run_single_in_docker $WHEELHOUSE
127113

128114
else

tools/test-wheels.sh

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/bin/bash
2+
#
3+
4+
# Test wheels in given directory.
5+
# Should preferably be run on OSX and requires Docker (for Linux tests).
6+
# Must be run from the top-level project directory.
7+
8+
set -e
9+
10+
if [[ -z $1 ]]; then
11+
echo "Usage: $0 <wheel-directory>"
12+
exit 1
13+
fi
14+
15+
if [[ ! -f tools/$(basename $0) ]]; then
16+
echo "Needs to be run from the top-level project directory"
17+
exit 1
18+
fi
19+
20+
21+
set -u
22+
23+
wheeldir="$1"
24+
25+
if [[ ! -d $wheeldir ]]; then
26+
echo "Wheel directory $wheeldir does not exist"
27+
exit 1
28+
fi
29+
30+
31+
echo "##################################"
32+
echo "#### Testing packages locally ####"
33+
echo "#### $wheeldir ####"
34+
echo "##################################"
35+
36+
echo "# Smoke testing locally"
37+
tools/smoketest.sh "$wheeldir"
38+
39+
echo "# Smoke testing on many linux distros"
40+
tools/test-manylinux.sh "$wheeldir"
41+
42+
echo "##################################"
43+
echo "#### Tests passed for ####"
44+
echo "#### $wheeldir ####"
45+
echo "##################################"
46+

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy