commit b7fd87644470ecb8d2cefc89188291f4b5ca4899 Author: Jim Meyering meyering@redhat.com Date: Wed Sep 21 17:55:33 2011 +0200
tests: add a test to exercise mongo-reconnect processing
* t/mongo-restart: New test. * t/Makefile.am (TESTS): Add it here. * NEWS (Bug fixes): Mention it.
NEWS | 3 ++ t/Makefile.am | 1 + t/mongo-restart | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 84 insertions(+), 0 deletions(-) --- diff --git a/NEWS b/NEWS index be681f9..c7467a9 100644 --- a/NEWS +++ b/NEWS @@ -4,6 +4,9 @@ iwhd NEWS -*- outline -*-
** Bug fixes
+ iwhd now continues to work properly when mongo dies and is restarted. + Before, it would dump core due to an unhandled SocketException. + iwhd's /etc/init.d startup script now reports failure reliably, for example when failing to start because no MongoDB server is running. Before it would print [FAILED], but mistakenly exit 0 (successful). diff --git a/t/Makefile.am b/t/Makefile.am index ae2bdf3..a3b39d7 100644 --- a/t/Makefile.am +++ b/t/Makefile.am @@ -20,6 +20,7 @@ TESTS = \ creation-code \ delete-missing \ exercise \ + mongo-restart \ provider \ replication \ auto \ diff --git a/t/mongo-restart b/t/mongo-restart new file mode 100755 index 0000000..1447952 --- /dev/null +++ b/t/mongo-restart @@ -0,0 +1,80 @@ +#!/bin/sh +# Ensure iwhd recovers after mongo stop/restart. +# Before 0.99 it did not. + +. "${srcdir=.}/init.sh"; path_prepend_ .. + +mkdir FS mongod iwhd || framework_failure_ mkdir failed + +ulimit -c unlimited +m_port=$(get_port $mongo_base_port $lock_dir/m-) \ + || fail_ "failed to get mongodb port" + +mongod --help > /dev/null || fail_ "the mongod program is not installed" + +mongod --port $m_port --pidfilepath mongod/pid --dbpath mongod > mongod.log 2>&1 & +mongo_pid=$! +cleanup_() { kill -9 $mongo_pid; } + +# Wait for up to 5 seconds for mongod to begin listening. +wait_for .1 50 'mongo localhost:$m_port < /dev/null' \ + || framework_failure_ mongod failed to start + +port=$(get_port 9095 $lock_dir/i-) || fail_ "failed to get iwhd port" + +printf '[{"path": "FS", "type": "fs", "name": "primary"}]\n' \ + > iwhd.cfg || fail=1 + +iwhd -v -p $port -c iwhd.cfg -d localhost:$m_port & +iwhd_pid=$! +cleanup_() { kill -9 $mongo_pid; kill $iwhd_pid; } + +# Wait for up to 5 seconds for iwhd to begin listening on $port. +wait_for .1 50 "curl -s http://localhost:$port" \ + || fail_ iwhd failed to listen + +curl_w() { curl --write-out '%{http_code}' "$@"; } + +# Show that bucket,object,attribute-creation all evoke 201. +creation_evokes_201() +{ + local bucket_name=$1 + + # Create a bucket. + local b=http://localhost:$port/$bucket_name + curl_w -XPUT $b > http-code || fail=1 + test "$(cat http-code)" = 201 || fail=1 + + # Create an object in that bucket. + local obj=$b/obj + curl_w -XPUT $obj > http-code || fail=1 + test "$(cat http-code)" = 201 || fail=1 + + # Create an attribute. + local attr=$obj/color + printf blue | curl_w -T - $attr > http-code || fail=1 + test "$(cat http-code)" = 201 || fail=1 +} + + +creation_evokes_201 b1 + +# So far, this is identical to the creation-code test. +# But now, we kill mongo and restart it, and then repeat the test. + +kill $mongo_pid + +# Wait for mongo to stop listening. +no_mongo() { mongo localhost:$m_port < /dev/null; test $? != 0; } +wait_for .1 50 no_mongo || fail_ failed to kill mongo + +mongod --port $m_port --pidfilepath mongod/pid --dbpath mongod & +mongo_pid=$! + +# Wait for up to 5 seconds for mongod to begin listening. +wait_for .1 50 'mongo localhost:$m_port < /dev/null' \ + || framework_failure_ mongod failed to start + +creation_evokes_201 b2 + +Exit $fail