Skip to content

Commit 4e9209f

Browse files
committed
tests: enable running tests inside pg_virtualenv
This mostly requires fixtures to create and destroy the test tablespace. pg_virtualenv itself needs to be wrapped around the call to ctest. The old way of running on the main database on the system still works as before. Currently enabled for posix-like systems only. Fixes #234.
1 parent 706f3a0 commit 4e9209f

File tree

4 files changed

+69
-5
lines changed

4 files changed

+69
-5
lines changed

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)