Skip to content

Commit 1caa0a8

Browse files
authored
Merge pull request #892 from openstreetmap/use-pg-virtualenv
Tests: enable running tests inside pg_virtualenv
2 parents 706f3a0 + 5482234 commit 1caa0a8

File tree

5 files changed

+81
-15
lines changed

5 files changed

+81
-15
lines changed

.travis.yml

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,22 +56,22 @@ matrix:
5656
# ---- Linux + CLANG ---------------------------
5757
- os: linux
5858
compiler: "clang-3.8"
59-
env: T="clang38_pg92_dbtest" RUNTEST="#Dbtest" LUAJIT_OPTION="OFF"
59+
env: T="clang38_pg92_dbtest" LUAJIT_OPTION="OFF"
6060
CXXFLAGS="-pedantic -Werror"
6161
CC=clang-3.8 CXX=clang++-3.8
6262
addons: *clang38_pg92
6363

6464
- os: linux
6565
compiler: "clang-7"
66-
env: T="clang7_pg96_dbtest_luajit" RUNTEST="#Dbtest" LUAJIT_OPTION="ON"
66+
env: T="clang7_pg96_dbtest_luajit" LUAJIT_OPTION="ON"
6767
CXXFLAGS="-pedantic -Werror"
6868
CC=clang-7 CXX=clang++-7
6969
addons: *clang7_pg96
7070

7171
# ---- OSX + CLANG ---------------------------
7272
- os: osx
7373
compiler: clang
74-
env: T="osx_clang_NoDB" RUNTEST="-L NoDB" LUAJIT_OPTION="OFF"
74+
env: T="osx_clang_NoDB" LUAJIT_OPTION="OFF" TEST_NODB=1
7575
CXXFLAGS="-pedantic -Werror"
7676
before_install:
7777
- brew install lua;
@@ -83,26 +83,23 @@ matrix:
8383
# ---- Linux + GCC ---------------------------
8484
- os: linux
8585
compiler: "gcc-4.8"
86-
env: T="gcc48_pg96_dbtest" RUNTEST="#Dbtest" LUAJIT_OPTION="OFF"
86+
env: T="gcc48_pg96_dbtest" LUAJIT_OPTION="OFF"
8787
CXXFLAGS="-pedantic -Werror"
8888
CC=gcc-4.8 CXX=g++-4.8
8989
addons: *gcc48_pg96
9090

9191
- os: linux
9292
compiler: gcc-8
93-
env: T="gcc8_pg96_dbtest_luajit" RUNTEST="#Dbtest" LUAJIT_OPTION="ON"
93+
env: T="gcc8_pg96_dbtest_luajit" LUAJIT_OPTION="ON"
9494
CXXFLAGS="-pedantic -Werror"
9595
CC=gcc-8 CXX=g++-8
9696
addons: *gcc8_pg96
9797

9898

9999
before_install:
100-
- sudo mkdir -p /extra/pg/tablespacetest # for the database test
101-
- sudo chown postgres:postgres /extra/pg/tablespacetest
102100
- dpkg -l | grep -E 'lua|proj|xml|bz2|postgis|zlib|boost|expat' # checking available versions
103101
before_script:
104102
- psql -U postgres -c "SELECT version()"
105-
- psql -U postgres -c "CREATE TABLESPACE tablespacetest LOCATION '/extra/pg/tablespacetest'"
106103
- psql -U postgres -c "CREATE EXTENSION postgis"
107104
- psql -U postgres -c "CREATE EXTENSION hstore"
108105
- psql -U postgres -c "SELECT PostGIS_Full_Version()"
@@ -115,9 +112,14 @@ script:
115112
- cmake .. -DBUILD_TESTS=ON -DCMAKE_BUILD_TYPE=Debug -DWITH_LUAJIT=$LUAJIT_OPTION
116113
- make -j2
117114
- echo "Running tests ... "
118-
- if [[ $RUNTEST ]]; then ctest -VV $RUNTEST; fi
115+
- if [[ $TEST_NODB ]]; then
116+
ctest -VV -L NoDB;
117+
else
118+
PG_VERSION=`psql -U postgres -t -c "SELECT version()" | head -n 1 | cut -d ' ' -f 3 | cut -d . -f 1-2`;
119+
pg_virtualenv -v $PG_VERSION ctest -VV;
120+
fi
119121
after_failure:
120122
- # rerun make, but verbosely
121123
make VERBOSE=1
122124

123-
# end of .travis
125+
# end of .travis

CONTRIBUTING.md

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,20 @@ sudo apt-get install python-psycopg2
7777
```
7878

7979
Most of these tests depend on being able to set up a database and run osm2pgsql
80-
against it. You need to ensure that PostgreSQL is running and that your user is
81-
a superuser of that system. To do that, run:
80+
against it. This is most easily done using ``pg_virtualenv``. Just run
81+
82+
```sh
83+
pg_virtualenv ctest
84+
```
85+
86+
``pg_virtualenv`` creates a separate postgres server instance. The test databases
87+
are created in this instance and the complete server is destroyed after the
88+
tests are finished. ctest also calls appropriate fixtures that create the
89+
separate tablespace required for some tests.
90+
91+
When running without ``pg_virtualenv``, you need to ensure that PostgreSQL is
92+
running and that your user is a superuser of that system. You also need to
93+
create an appropriate test tablespace manually. To do that, run:
8294

8395
```sh
8496
sudo -u postgres createuser -s $USER
@@ -94,9 +106,6 @@ to be a bug, please check to see if it is a known issue at
94106
https://github.com/openstreetmap/osm2pgsql/issues and, if it's not
95107
already known, report it there.
96108

97-
If running the tests in a virtual machine, allocate sufficient disk space for a
98-
20GB flat nodes file.
99-
100109
### Performance Testing
101110

102111
If performance testing with a full planet import is required, indicate what

tests/CMakeLists.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,23 @@ endforeach()
6363
set_property(TEST test-middle-flat PROPERTY LABELS FlatNodes)
6464
set_property(TEST test-output-pgsql PROPERTY LABELS FlatNodes)
6565

66+
# Fixture for creating test tablespace under a pg_virtualenv
67+
if (NOT WIN32)
68+
message(STATUS "Added tablespace fixture...")
69+
add_test(NAME FixtureTablespaceSetup
70+
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/fixture-tablespace-setup
71+
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
72+
add_test(NAME FixtureTablespaceCleanup
73+
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/fixture-tablespace-cleanup
74+
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
75+
76+
set_tests_properties(FixtureTablespaceSetup PROPERTIES FIXTURES_SETUP Tablespace)
77+
set_tests_properties(FixtureTablespaceCleanup PROPERTIES FIXTURES_CLEANUP Tablespace)
78+
endif()
79+
80+
set_tests_properties(test-output-pgsql-tablespace
81+
PROPERTIES FIXTURES_REQUIRED Tablespace)
82+
6683
if (NOT HAVE_LUA)
6784
# these tests require LUA support
6885
set_tests_properties(test-output-multi-poly-trivial PROPERTIES WILL_FAIL on)
@@ -77,6 +94,8 @@ if (PYTHONINTERP_FOUND)
7794
set_tests_properties(regression-test-pbf PROPERTIES TIMEOUT ${TESTING_TIMEOUT})
7895
set_tests_properties(regression-test-pbf
7996
PROPERTIES ENVIRONMENT "HAVE_LUA=${LUA_FOUND}")
97+
set_tests_properties(regression-test-pbf
98+
PROPERTIES FIXTURES_REQUIRED Tablespace)
8099
message(STATUS "Added test: regression-test-pbf (needs Python with psycopg2 module)")
81100
else()
82101
message(WARNING "Can not find python, regression test disabled")

tests/fixture-tablespace-cleanup

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/sh
2+
#
3+
# Remove any custom tablespaces we might have created.
4+
5+
BASEDIR=`pwd`
6+
7+
TBLDIR=${BASEDIR}/osm2pgsql-test-tablespace
8+
9+
if find $TBLDIR -maxdepth 1 -mindepth 1 -type d -name 'PG*'; then
10+
rm -r $TBLDIR/PG*
11+
fi

tests/fixture-tablespace-setup

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/sh
2+
#
3+
# Creates the required tablespace for tests.
4+
#
5+
# Only do this when we are running under pg_virtualenv.
6+
# Then the tablespace can be owned by the current user.
7+
8+
if [ "x$PG_CLUSTER_CONF_ROOT" != "x" ]; then
9+
BASEDIR=`pwd`
10+
11+
TBLDIR=${BASEDIR}/osm2pgsql-test-tablespace
12+
13+
if [ -d "$TBLDIR" ]; then
14+
echo "Tablespace directory already exists. Cleaning up."
15+
16+
if find $TBLDIR -maxdepth 1 -mindepth 1 -type d -name 'PG*'; then
17+
rm -r $TBLDIR/PG*
18+
fi
19+
else
20+
mkdir $TBLDIR
21+
chmod 777 $TBLDIR
22+
fi
23+
24+
psql -c "CREATE TABLESPACE tablespacetest LOCATION '$TBLDIR'" postgres
25+
fi

0 commit comments

Comments
 (0)