diff options
3 files changed, 56 insertions, 2 deletions
diff --git a/staging_vespalib/src/tests/state_server/CMakeLists.txt b/staging_vespalib/src/tests/state_server/CMakeLists.txt index ea72a021f46..cd179a6caeb 100644 --- a/staging_vespalib/src/tests/state_server/CMakeLists.txt +++ b/staging_vespalib/src/tests/state_server/CMakeLists.txt @@ -5,4 +5,4 @@ vespa_add_executable(staging_vespalib_state_server_test_app TEST DEPENDS staging_vespalib ) -vespa_add_test(NAME staging_vespalib_state_server_test_app NO_VALGRIND NO_VALGRIND COMMAND staging_vespalib_state_server_test_app) +vespa_add_test(NAME staging_vespalib_state_server_test_app NO_VALGRIND NO_VALGRIND COMMAND staging_vespalib_state_server_test_app ENVIRONMENT "VESPA_HOME=.") diff --git a/staging_vespalib/src/tests/state_server/state_server_test.cpp b/staging_vespalib/src/tests/state_server/state_server_test.cpp index d4071526a79..6c7397a1719 100644 --- a/staging_vespalib/src/tests/state_server/state_server_test.cpp +++ b/staging_vespalib/src/tests/state_server/state_server_test.cpp @@ -1,5 +1,10 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +#include <fcntl.h> +#include <stdlib.h> +#include <sys/stat.h> +#include <sys/types.h> + #include <vespa/vespalib/testkit/test_kit.h> #include <vespa/vespalib/util/host_name.h> #include <vespa/vespalib/net/state_server.h> @@ -491,4 +496,10 @@ TEST("require that generic state can be explored") { check_json(json_list_two, state_handler.get(host_tag, root_path + "list/two", empty_params)); } -TEST_MAIN_WITH_PROCESS_PROXY() { TEST_RUN_ALL(); } +TEST_MAIN_WITH_PROCESS_PROXY() { + mkdir("var", S_IRWXU); + mkdir("var/run", S_IRWXU); + TEST_RUN_ALL(); + rmdir("var/run"); + rmdir("var"); +} diff --git a/staging_vespalib/src/vespa/vespalib/net/simple_health_producer.cpp b/staging_vespalib/src/vespa/vespalib/net/simple_health_producer.cpp index 4815fc7096f..651dab97e68 100644 --- a/staging_vespalib/src/vespa/vespalib/net/simple_health_producer.cpp +++ b/staging_vespalib/src/vespa/vespalib/net/simple_health_producer.cpp @@ -1,6 +1,46 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "simple_health_producer.h" +#include <vespa/defaults.h> +#include <fcntl.h> +#include <sys/stat.h> +#include <sys/types.h> +#include <unistd.h> + +namespace { +struct DiskPing { + std::string path; + + DiskPing() + : path(vespa::Defaults::underVespaHome("var/run/diskping.")) + { + int pid = getpid(); + while (pid > 0) { + char c = '0' + (pid % 10); + path.append(1, c); + pid /= 10; + } + } + bool failed() { + const char *fn = path.c_str(); + ::unlink(fn); + int fd = ::creat(fn, S_IRWXU); + if (fd < 0) { + return true; + } + int wr = ::write(fd, "foo\n", 4); + int cr = ::close(fd); + ::unlink(fn); + return (wr != 4 || cr != 0); + } +}; + +bool diskFailed() { + static DiskPing disk; + return disk.failed(); +} + +} namespace vespalib { @@ -33,6 +73,9 @@ HealthProducer::Health SimpleHealthProducer::getHealth() const { LockGuard guard(_lock); + if (_health.ok && diskFailed()) { + return Health(false, "disk ping failed"); + } return _health; } |