diff options
author | Luke Chen <luke.chen@mongodb.com> | 2021-10-15 15:40:03 +1100 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-10-15 05:06:43 +0000 |
commit | 6cbe5d9eb41e418c7ed145a5ae85adec76addf41 (patch) | |
tree | 11db40fb6beafe50122f28cc2ff7087ee3d80aaf | |
parent | 574a3b446d1347047e0d35104c1108e4a2ceae95 (diff) | |
download | mongo-6cbe5d9eb41e418c7ed145a5ae85adec76addf41.tar.gz |
Import wiredtiger: e930e8d0cd4c3330783e711253eae2923b1e2e3f from branch mongodb-master
ref: a1f8165720..e930e8d0cd
for: 5.2.0
WT-8116 Fix issues related to inheritance in the cpp testing framework
20 files changed, 149 insertions, 48 deletions
diff --git a/src/third_party/wiredtiger/import.data b/src/third_party/wiredtiger/import.data index ddfc7cccd61..56c4501903a 100644 --- a/src/third_party/wiredtiger/import.data +++ b/src/third_party/wiredtiger/import.data @@ -2,5 +2,5 @@ "vendor": "wiredtiger", "github": "wiredtiger/wiredtiger.git", "branch": "mongodb-master", - "commit": "a1f8165720c8fc8dfacb90e4d9e398ccca9edd29" + "commit": "e930e8d0cd4c3330783e711253eae2923b1e2e3f" } diff --git a/src/third_party/wiredtiger/test/cppsuite/Makefile.am b/src/third_party/wiredtiger/test/cppsuite/Makefile.am index 5e896ce2e04..8221f882014 100644 --- a/src/third_party/wiredtiger/test/cppsuite/Makefile.am +++ b/src/third_party/wiredtiger/test/cppsuite/Makefile.am @@ -15,6 +15,7 @@ test_harness = test_harness/core/component.cxx \ test_harness/core/configuration.cxx \ test_harness/core/throttle.cxx \ test_harness/util/logger.cxx \ + test_harness/util/scoped_connection.cxx \ test_harness/util/scoped_types.cxx \ test_harness/workload/database_model.cxx \ test_harness/workload/database_operation.cxx \ diff --git a/src/third_party/wiredtiger/test/cppsuite/test_harness/connection_manager.cxx b/src/third_party/wiredtiger/test/cppsuite/test_harness/connection_manager.cxx index 8a8b75b7b8f..292cfbbfeab 100644 --- a/src/third_party/wiredtiger/test/cppsuite/test_harness/connection_manager.cxx +++ b/src/third_party/wiredtiger/test/cppsuite/test_harness/connection_manager.cxx @@ -29,6 +29,7 @@ #include "connection_manager.h" #include "util/api_const.h" #include "util/logger.h" +#include "util/scoped_connection.h" namespace test_harness { connection_manager & @@ -73,9 +74,8 @@ connection_manager::create_session() testutil_die(EINVAL, "Connection is NULL"); } - _conn_mutex.lock(); + std::lock_guard<std::mutex> lg(_conn_mutex); scoped_session session(_conn); - _conn_mutex.unlock(); return (session); } @@ -92,9 +92,8 @@ connection_manager::get_connection() void connection_manager::set_timestamp(const std::string &config) { - _conn_mutex.lock(); + std::lock_guard<std::mutex> lg(_conn_mutex); testutil_check(_conn->set_timestamp(_conn, config.c_str())); - _conn_mutex.unlock(); } connection_manager::connection_manager() {} diff --git a/src/third_party/wiredtiger/test/cppsuite/test_harness/connection_manager.h b/src/third_party/wiredtiger/test/cppsuite/test_harness/connection_manager.h index a5d44903717..2fef81d2af8 100644 --- a/src/third_party/wiredtiger/test/cppsuite/test_harness/connection_manager.h +++ b/src/third_party/wiredtiger/test/cppsuite/test_harness/connection_manager.h @@ -61,7 +61,7 @@ class connection_manager { connection_manager &operator=(connection_manager const &) = delete; void close(); - void create(const std::string &config, const std::string &home = DEFAULT_DIR); + void create(const std::string &config, const std::string &home); scoped_session create_session(); WT_CONNECTION *get_connection(); diff --git a/src/third_party/wiredtiger/test/cppsuite/test_harness/core/component.h b/src/third_party/wiredtiger/test/cppsuite/test_harness/core/component.h index 398ca11e442..65a2215cdac 100644 --- a/src/third_party/wiredtiger/test/cppsuite/test_harness/core/component.h +++ b/src/third_party/wiredtiger/test/cppsuite/test_harness/core/component.h @@ -39,7 +39,7 @@ namespace test_harness { */ class component { public: - component(const std::string &name, configuration *config); + explicit component(const std::string &name, configuration *config); virtual ~component(); /* Delete the copy constructor and the assignment operator. */ diff --git a/src/third_party/wiredtiger/test/cppsuite/test_harness/core/configuration.h b/src/third_party/wiredtiger/test/cppsuite/test_harness/core/configuration.h index f34465904ad..4c7aeb0ac3f 100644 --- a/src/third_party/wiredtiger/test/cppsuite/test_harness/core/configuration.h +++ b/src/third_party/wiredtiger/test/cppsuite/test_harness/core/configuration.h @@ -60,8 +60,8 @@ split_string(const std::string &str, const char delim) class configuration { public: - configuration(const std::string &test_config_name, const std::string &config); - configuration(const WT_CONFIG_ITEM &nested); + explicit configuration(const std::string &test_config_name, const std::string &config); + explicit configuration(const WT_CONFIG_ITEM &nested); ~configuration(); diff --git a/src/third_party/wiredtiger/test/cppsuite/test_harness/runtime_monitor.cxx b/src/third_party/wiredtiger/test/cppsuite/test_harness/runtime_monitor.cxx index 0e454a4f4f0..d123ae9f7c8 100644 --- a/src/third_party/wiredtiger/test/cppsuite/test_harness/runtime_monitor.cxx +++ b/src/third_party/wiredtiger/test/cppsuite/test_harness/runtime_monitor.cxx @@ -80,7 +80,7 @@ runtime_statistic::enabled() const /* cache_limit_statistic class implementation */ cache_limit_statistic::cache_limit_statistic(configuration *config) : runtime_statistic(config) { - limit = config->get_int(LIMIT); + _limit = config->get_int(LIMIT); } void @@ -98,9 +98,9 @@ cache_limit_statistic::check(scoped_cursor &cursor) * point conversion errors. */ use_percent = ((cache_bytes_image + cache_bytes_other + 0.0) / cache_bytes_max) * 100; - if (use_percent > limit) { + if (use_percent > _limit) { const std::string error_string = - "runtime_monitor: Cache usage exceeded during test! Limit: " + std::to_string(limit) + + "runtime_monitor: Cache usage exceeded during test! Limit: " + std::to_string(_limit) + " usage: " + std::to_string(use_percent); testutil_die(-1, error_string.c_str()); } else diff --git a/src/third_party/wiredtiger/test/cppsuite/test_harness/runtime_monitor.h b/src/third_party/wiredtiger/test/cppsuite/test_harness/runtime_monitor.h index 0f63585290d..4ee0d1055ba 100644 --- a/src/third_party/wiredtiger/test/cppsuite/test_harness/runtime_monitor.h +++ b/src/third_party/wiredtiger/test/cppsuite/test_harness/runtime_monitor.h @@ -48,13 +48,11 @@ namespace test_harness { class runtime_statistic { public: explicit runtime_statistic(configuration *config); + virtual ~runtime_statistic() = default; /* Check that the given statistic is within bounds. */ virtual void check(scoped_cursor &cursor) = 0; - /* Suppress warning about destructor being non-virtual. */ - virtual ~runtime_statistic() {} - bool enabled() const; protected: @@ -64,16 +62,17 @@ class runtime_statistic { class cache_limit_statistic : public runtime_statistic { public: explicit cache_limit_statistic(configuration *config); + virtual ~cache_limit_statistic() = default; void check(scoped_cursor &cursor) override final; private: - int64_t limit; + int64_t _limit; }; class db_size_statistic : public runtime_statistic { public: - db_size_statistic(configuration *config, database &database); + explicit db_size_statistic(configuration *config, database &database); virtual ~db_size_statistic() = default; /* Don't need the stat cursor for this. */ @@ -90,7 +89,6 @@ class db_size_statistic : public runtime_statistic { class postrun_statistic_check { public: explicit postrun_statistic_check(configuration *config); - virtual ~postrun_statistic_check() = default; void check(scoped_cursor &cursor) const; @@ -119,7 +117,7 @@ class runtime_monitor : public component { static void get_stat(scoped_cursor &, int, int64_t *); public: - runtime_monitor(configuration *config, database &database); + explicit runtime_monitor(configuration *config, database &database); ~runtime_monitor(); /* Delete the copy constructor and the assignment operator. */ diff --git a/src/third_party/wiredtiger/test/cppsuite/test_harness/test.cxx b/src/third_party/wiredtiger/test/cppsuite/test_harness/test.cxx index 4ce0de2e381..8cdea3170df 100644 --- a/src/third_party/wiredtiger/test/cppsuite/test_harness/test.cxx +++ b/src/third_party/wiredtiger/test/cppsuite/test_harness/test.cxx @@ -119,8 +119,12 @@ test::run() /* Add the user supplied wiredtiger open config. */ db_create_config += _args.wt_open_config; - /* Set up the test environment. */ - connection_manager::instance().create(db_create_config); + /* + * Set up the test environment. A smart pointer is used here so that the connection can + * automatically be closed by the scoped_connection's destructor when the test finishes and the + * pointer goes out of scope. + */ + _scoped_conn = std::make_shared<scoped_connection>(db_create_config); /* Initiate the load stage of each component. */ for (const auto &it : _components) diff --git a/src/third_party/wiredtiger/test/cppsuite/test_harness/test.h b/src/third_party/wiredtiger/test/cppsuite/test_harness/test.h index 8c5e2d17434..ba899339bb0 100644 --- a/src/third_party/wiredtiger/test/cppsuite/test_harness/test.h +++ b/src/third_party/wiredtiger/test/cppsuite/test_harness/test.h @@ -39,6 +39,7 @@ extern "C" { #include "checkpoint_manager.h" #include "connection_manager.h" #include "runtime_monitor.h" +#include "util/scoped_connection.h" #include "workload/database_operation.h" #include "workload_generator.h" @@ -59,8 +60,8 @@ class test_args { */ class test : public database_operation { public: - test(const test_args &args); - ~test(); + explicit test(const test_args &args); + virtual ~test(); /* Delete the copy constructor and the assignment operator. */ test(const test &) = delete; @@ -92,18 +93,8 @@ class test : public database_operation { timestamp_manager *_timestamp_manager = nullptr; workload_generator *_workload_generator = nullptr; workload_tracking *_workload_tracking = nullptr; - /* - * FIX-ME-Test-Framework: We can't put this code in the destructor of `test` since it will run - * before the destructors of each of our members (meaning that sessions will get closed after - * the connection gets closed). To work around this, we've added a member with a destructor that - * closes the connection. - */ - struct connection_closer { - ~connection_closer() - { - connection_manager::instance().close(); - } - } _connection_closer; + + std::shared_ptr<scoped_connection> _scoped_conn; database _database; }; } // namespace test_harness diff --git a/src/third_party/wiredtiger/test/cppsuite/test_harness/timestamp_manager.h b/src/third_party/wiredtiger/test/cppsuite/test_harness/timestamp_manager.h index e510614d077..c10d10df5c0 100644 --- a/src/third_party/wiredtiger/test/cppsuite/test_harness/timestamp_manager.h +++ b/src/third_party/wiredtiger/test/cppsuite/test_harness/timestamp_manager.h @@ -50,7 +50,8 @@ class timestamp_manager : public component { static const std::string decimal_to_hex(uint64_t value); public: - timestamp_manager(configuration *config); + explicit timestamp_manager(configuration *config); + virtual ~timestamp_manager() = default; void load() override final; void do_work() override final; diff --git a/src/third_party/wiredtiger/test/cppsuite/test_harness/util/scoped_connection.cxx b/src/third_party/wiredtiger/test/cppsuite/test_harness/util/scoped_connection.cxx new file mode 100644 index 00000000000..39a8fede916 --- /dev/null +++ b/src/third_party/wiredtiger/test/cppsuite/test_harness/util/scoped_connection.cxx @@ -0,0 +1,46 @@ +/*- + * Public Domain 2014-present MongoDB, Inc. + * Public Domain 2008-2014 WiredTiger, Inc. + * + * This is free and unencumbered software released into the public domain. + * + * Anyone is free to copy, modify, publish, use, compile, sell, or + * distribute this software, either in source code form or as a compiled + * binary, for any purpose, commercial or non-commercial, and by any + * means. + * + * In jurisdictions that recognize copyright laws, the author or authors + * of this software dedicate any and all copyright interest in the + * software to the public domain. We make this dedication for the benefit + * of the public at large and to the detriment of our heirs and + * successors. We intend this dedication to be an overt act of + * relinquishment in perpetuity of all present and future rights to this + * software under copyright law. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ +#include <iostream> +#include <utility> + +#include "../connection_manager.h" +#include "scoped_connection.h" + +namespace test_harness { + +scoped_connection::scoped_connection(const std::string &db_conn_config, const std::string &home) +{ + connection_manager::instance().create(db_conn_config, home); +} + +scoped_connection::~scoped_connection() +{ + connection_manager::instance().close(); +} + +} // namespace test_harness diff --git a/src/third_party/wiredtiger/test/cppsuite/test_harness/util/scoped_connection.h b/src/third_party/wiredtiger/test/cppsuite/test_harness/util/scoped_connection.h new file mode 100644 index 00000000000..6e999b6db54 --- /dev/null +++ b/src/third_party/wiredtiger/test/cppsuite/test_harness/util/scoped_connection.h @@ -0,0 +1,56 @@ +/*- + * Public Domain 2014-present MongoDB, Inc. + * Public Domain 2008-2014 WiredTiger, Inc. + * + * This is free and unencumbered software released into the public domain. + * + * Anyone is free to copy, modify, publish, use, compile, sell, or + * distribute this software, either in source code form or as a compiled + * binary, for any purpose, commercial or non-commercial, and by any + * means. + * + * In jurisdictions that recognize copyright laws, the author or authors + * of this software dedicate any and all copyright interest in the + * software to the public domain. We make this dedication for the benefit + * of the public at large and to the detriment of our heirs and + * successors. We intend this dedication to be an overt act of + * relinquishment in perpetuity of all present and future rights to this + * software under copyright law. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ + +#ifndef SCOPED_CONNECTION_H +#define SCOPED_CONNECTION_H + +/* Following definitions are required in order to use printing format specifiers in C++. */ +#ifndef __STDC_LIMIT_MACROS +#define __STDC_LIMIT_MACROS +#endif +#ifndef __STDC_FORMAT_MACROS +#define __STDC_FORMAT_MACROS +#endif + +extern "C" { +#include "test_util.h" +} + +#include "../connection_manager.h" + +namespace test_harness { + +class scoped_connection { + public: + explicit scoped_connection( + const std::string &db_conn_config, const std::string &home = DEFAULT_DIR); + ~scoped_connection(); +}; + +} // namespace test_harness +#endif diff --git a/src/third_party/wiredtiger/test/cppsuite/test_harness/util/scoped_types.h b/src/third_party/wiredtiger/test/cppsuite/test_harness/util/scoped_types.h index edb38e3e22c..71fc24f6c26 100644 --- a/src/third_party/wiredtiger/test/cppsuite/test_harness/util/scoped_types.h +++ b/src/third_party/wiredtiger/test/cppsuite/test_harness/util/scoped_types.h @@ -45,12 +45,12 @@ namespace test_harness { class scoped_cursor { public: scoped_cursor() = default; - scoped_cursor(WT_SESSION *session, const char *uri, const char *cfg); + explicit scoped_cursor(WT_SESSION *session, const char *uri, const char *cfg); /* Moving is ok but copying is not. */ scoped_cursor(scoped_cursor &&other); - virtual ~scoped_cursor(); + ~scoped_cursor(); scoped_cursor &operator=(scoped_cursor &&other); scoped_cursor(const scoped_cursor &) = delete; @@ -72,7 +72,7 @@ class scoped_session { scoped_session() = default; explicit scoped_session(WT_CONNECTION *conn); - virtual ~scoped_session(); + ~scoped_session(); /* Moving is ok but copying is not. */ scoped_session(scoped_session &&other); diff --git a/src/third_party/wiredtiger/test/cppsuite/test_harness/workload/database_model.h b/src/third_party/wiredtiger/test/cppsuite/test_harness/workload/database_model.h index edbb5bd2675..c8d54524873 100644 --- a/src/third_party/wiredtiger/test/cppsuite/test_harness/workload/database_model.h +++ b/src/third_party/wiredtiger/test/cppsuite/test_harness/workload/database_model.h @@ -45,7 +45,7 @@ typedef std::string key_value_t; /* A collection is made of mapped key value objects. */ class collection { public: - collection(const uint64_t id, const uint64_t key_count, const std::string &name); + explicit collection(const uint64_t id, const uint64_t key_count, const std::string &name); /* Copies aren't allowed. */ collection(const collection &) = delete; diff --git a/src/third_party/wiredtiger/test/cppsuite/test_harness/workload/database_operation.h b/src/third_party/wiredtiger/test/cppsuite/test_harness/workload/database_operation.h index c8dd7370b0f..767ef50c5b7 100644 --- a/src/third_party/wiredtiger/test/cppsuite/test_harness/workload/database_operation.h +++ b/src/third_party/wiredtiger/test/cppsuite/test_harness/workload/database_operation.h @@ -57,6 +57,8 @@ class database_operation { * Basic update operation that chooses a random key and updates it. */ virtual void update_operation(thread_context *tc); + + virtual ~database_operation() = default; }; } // namespace test_harness #endif diff --git a/src/third_party/wiredtiger/test/cppsuite/test_harness/workload/workload_tracking.h b/src/third_party/wiredtiger/test/cppsuite/test_harness/workload/workload_tracking.h index 704f26ac84b..b6c232376c7 100644 --- a/src/third_party/wiredtiger/test/cppsuite/test_harness/workload/workload_tracking.h +++ b/src/third_party/wiredtiger/test/cppsuite/test_harness/workload/workload_tracking.h @@ -58,9 +58,10 @@ enum class tracking_operation { CREATE_COLLECTION, DELETE_COLLECTION, DELETE_KEY /* Class used to track operations performed on collections */ class workload_tracking : public component { public: - workload_tracking(configuration *_config, const std::string &operation_table_config, + explicit workload_tracking(configuration *_config, const std::string &operation_table_config, const std::string &operation_table_name, const std::string &schema_table_config, const std::string &schema_table_name, const bool use_compression, timestamp_manager &tsm); + virtual ~workload_tracking() = default; const std::string &get_schema_table_name() const; const std::string &get_operation_table_name() const; diff --git a/src/third_party/wiredtiger/test/cppsuite/test_harness/workload_generator.h b/src/third_party/wiredtiger/test/cppsuite/test_harness/workload_generator.h index e29410f6116..78950b18677 100644 --- a/src/third_party/wiredtiger/test/cppsuite/test_harness/workload_generator.h +++ b/src/third_party/wiredtiger/test/cppsuite/test_harness/workload_generator.h @@ -48,7 +48,7 @@ namespace test_harness { */ class operation_config { public: - operation_config(configuration *config, thread_type type); + explicit operation_config(configuration *config, thread_type type); /* Returns a function pointer to the member function of the supplied database operation. */ std::function<void(test_harness::thread_context *)> get_func(database_operation *dbo); @@ -64,7 +64,7 @@ class operation_config { */ class workload_generator : public component { public: - workload_generator(configuration *configuration, database_operation *db_operation, + explicit workload_generator(configuration *configuration, database_operation *db_operation, timestamp_manager *timestamp_manager, workload_tracking *tracking, database &database); ~workload_generator(); diff --git a/src/third_party/wiredtiger/test/cppsuite/tests/csuite_style_example_test.cxx b/src/third_party/wiredtiger/test/cppsuite/tests/csuite_style_example_test.cxx index d0059880446..bcacf115665 100644 --- a/src/third_party/wiredtiger/test/cppsuite/tests/csuite_style_example_test.cxx +++ b/src/third_party/wiredtiger/test/cppsuite/tests/csuite_style_example_test.cxx @@ -37,6 +37,7 @@ #include "test_harness/thread_manager.h" #include "test_harness/util/api_const.h" #include "test_harness/util/logger.h" +#include "test_harness/util/scoped_connection.h" #include "test_harness/workload/random_generator.h" extern "C" { @@ -94,7 +95,11 @@ main(int argc, char *argv[]) /* Create a connection, set the cache size and specify the home directory. */ const std::string conn_config = std::string(CONNECTION_CREATE) + ",cache_size=500MB"; const std::string home_dir = std::string(DEFAULT_DIR) + '_' + progname; - connection_manager::instance().create(conn_config, home_dir); + /* + * A smart pointer is used here so that the connection can automatically be closed by the + * scoped_connection's destructor when the test finishes and the pointer goes out of scope. + */ + std::unique_ptr<scoped_connection> scoped_conn(new scoped_connection(conn_config, home_dir)); WT_CONNECTION *conn = connection_manager::instance().get_connection(); /* Open different sessions. */ @@ -159,9 +164,6 @@ main(int argc, char *argv[]) for (auto c : cursors) testutil_check(c->close(c)); - /* Close the connection. */ - connection_manager::instance().close(); - /* Another message. */ logger::log_msg(LOG_INFO, "End of test."); diff --git a/src/third_party/wiredtiger/test/cppsuite/tests/example_test.cxx b/src/third_party/wiredtiger/test/cppsuite/tests/example_test.cxx index 4b49ad2b148..c5f344ac1df 100644 --- a/src/third_party/wiredtiger/test/cppsuite/tests/example_test.cxx +++ b/src/third_party/wiredtiger/test/cppsuite/tests/example_test.cxx @@ -37,7 +37,7 @@ class example_test : public test_harness::test { example_test(const test_harness::test_args &args) : test(args) {} void - run() + run() override final { /* You can remove the call to the base class to fully customized your test. */ test::run(); |