diff options
author | Yingxin <yingxin.cheng@intel.com> | 2018-08-20 10:05:46 +0200 |
---|---|---|
committer | Yingxin <yingxin.cheng@intel.com> | 2018-08-21 21:04:42 +0200 |
commit | ca8ccb5b43d18882dad79b655a6ae2ea791684cd (patch) | |
tree | 4193224049c6a5de23992b843dc950a0c7bc9984 /src | |
parent | crimson/common: apply config changes also on shard.0 (diff) | |
download | ceph-ca8ccb5b43d18882dad79b655a6ae2ea791684cd.tar.xz ceph-ca8ccb5b43d18882dad79b655a6ae2ea791684cd.zip |
crimson/test: improve test_config with observers
Signed-off-by: Yingxin <yingxin.cheng@intel.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/test/crimson/test_config.cc | 59 |
1 files changed, 54 insertions, 5 deletions
diff --git a/src/test/crimson/test_config.cc b/src/test/crimson/test_config.cc index 5d0c104b8fc..fd81d328bde 100644 --- a/src/test/crimson/test_config.cc +++ b/src/test/crimson/test_config.cc @@ -1,26 +1,75 @@ #include <chrono> +#include <string> #include <numeric> #include <seastar/core/app-template.hh> #include <seastar/core/sharded.hh> +#include "common/config_obs.h" #include "crimson/common/config_proxy.h" using Config = ceph::common::ConfigProxy; +const std::string test_uint_option = "osd_max_pgls"; +const uint64_t INVALID_VALUE = (uint64_t)(-1); + +class ConfigObs : public ceph::internal::md_config_obs_impl<Config> { + uint64_t last_change = INVALID_VALUE; + uint64_t num_changes = 0; + + const char** get_tracked_conf_keys() const override { + static const char* keys[] = { + test_uint_option.c_str(), + nullptr, + }; + return keys; + } + void handle_conf_change(const Config& conf, + const std::set <std::string> &changes) override{ + if (changes.count(test_uint_option)) { + last_change = conf.get_val<uint64_t>(test_uint_option); + num_changes += 1; + } + } +public: + ConfigObs() { + ceph::common::local_conf().add_observer(this); + } + + uint64_t get_last_change() const { return last_change; } + uint64_t get_num_changes() const { return num_changes; } + seastar::future<> stop() { + ceph::common::local_conf().remove_observer(this); + return seastar::now(); + } +}; + +seastar::sharded<ConfigObs> sharded_cobs; static seastar::future<> test_config() { return ceph::common::sharded_conf().start().then([] { return ceph::common::sharded_conf().invoke_on(0, &Config::start); }).then([] { + return sharded_cobs.start(); + }).then([] { return ceph::common::sharded_conf().invoke_on_all([](Config& config) { - return config.set_val("osd_tracing", "true"); + return config.set_val(test_uint_option, + std::to_string(seastar::engine().cpu_id())); }); }).then([] { - return ceph::common::sharded_conf().invoke_on_all([](Config& config) { - if (!config.get_val<bool>("osd_tracing")) { - throw std::runtime_error("run osd_tracing"); + auto expected = ceph::common::local_conf().get_val<uint64_t>(test_uint_option); + return ceph::common::sharded_conf().invoke_on_all([expected](Config& config) { + if (expected != config.get_val<uint64_t>(test_uint_option)) { + throw std::runtime_error("configurations don't match"); + } + if (expected != sharded_cobs.local().get_last_change()) { + throw std::runtime_error("last applied changes don't match the latest config"); + } + if (seastar::smp::count != sharded_cobs.local().get_num_changes()) { + throw std::runtime_error("num changes don't match actual changes"); } }); - }).then([] { + }).finally([] { + return sharded_cobs.stop(); + }).finally([] { return ceph::common::sharded_conf().stop(); }); } |