Skip to content

Commit aca4675

Browse files
SourceR85Steven John Lange
andauthored
(#8656) - fix concurrent test-server errors
Co-authored-by: Steven John Lange <s.lange@hz-deutschland.de>
1 parent 4c92c94 commit aca4675

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

bin/run-test.sh

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ export VIEW_ADAPTERS
1212
pouchdb-setup-server() {
1313
# in CI, link pouchdb-servers dependencies on pouchdb
1414
# modules to the current implementations
15+
if [ -d "pouchdb-server-install" ]; then
16+
# pouchdb server already running
17+
exit 0
18+
fi
1519
mkdir pouchdb-server-install
1620
cd pouchdb-server-install
1721
npm init -y
@@ -54,6 +58,14 @@ pouchdb-link-server-modules() {
5458
cd ..
5559
}
5660

61+
search-free-port() {
62+
EXPRESS_PORT=3000
63+
while (: < /dev/tcp/127.0.0.1/$EXPRESS_PORT) 2>/dev/null; do
64+
((EXPRESS_PORT++))
65+
done
66+
export PORT=$EXPRESS_PORT
67+
}
68+
5769
pouchdb-build-node() {
5870
if [[ $BUILD_NODE_DONE -ne 1 ]]; then
5971
npm run build-node
@@ -75,9 +87,10 @@ if [[ ! -z $SERVER ]]; then
7587
fi
7688
elif [ "$SERVER" == "pouchdb-express-router" ]; then
7789
pouchdb-build-node
90+
search-free-port
7891
node ./tests/misc/pouchdb-express-router.js &
7992
export SERVER_PID=$!
80-
export COUCH_HOST='http://127.0.0.1:3000'
93+
export COUCH_HOST="http://127.0.0.1:${PORT}"
8194
elif [ "$SERVER" == "express-pouchdb-minimum" ]; then
8295
pouchdb-build-node
8396
node ./tests/misc/express-pouchdb-minimum-for-pouchdb.js &

bin/test-node.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ else
1212
fi
1313

1414
if [ $TYPE = "integration" ]; then
15-
node bin/down-server.js 3010 & export DOWN_SERVER_PID=$!
15+
if (: < /dev/tcp/127.0.0.1/3010) 2>/dev/null; then
16+
echo "down-server port already in use"
17+
else
18+
node bin/down-server.js 3010 & export DOWN_SERVER_PID=$!
19+
fi
1620

1721
TESTS_PATH="tests/integration/test.*.js"
1822
fi

0 commit comments

Comments
 (0)