-
Notifications
You must be signed in to change notification settings - Fork 597
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test_utils: add scoped config resetter #13146
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright 2023 Redpanda Data, Inc. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.md | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0 | ||
|
||
#include "config/configuration.h" | ||
#include "test_utils/scoped_config.h" | ||
|
||
#include <seastar/testing/thread_test_case.hh> | ||
|
||
// Test that when multiple test cases update a config using the | ||
// scoped_config, it is reset in between each one. | ||
|
||
SEASTAR_THREAD_TEST_CASE(test_scoped_config_a) { | ||
BOOST_REQUIRE_MESSAGE( | ||
!config::shard_local_cfg().cluster_id().has_value(), | ||
config::shard_local_cfg().cluster_id()->c_str()); | ||
scoped_config cfg; | ||
cfg.get("cluster_id").set_value(std::make_optional<ss::sstring>("a")); | ||
} | ||
|
||
SEASTAR_THREAD_TEST_CASE(test_scoped_config_b) { | ||
BOOST_REQUIRE_MESSAGE( | ||
!config::shard_local_cfg().cluster_id().has_value(), | ||
config::shard_local_cfg().cluster_id()->c_str()); | ||
scoped_config cfg; | ||
cfg.get("cluster_id").set_value(std::make_optional<ss::sstring>("b")); | ||
} | ||
|
||
SEASTAR_THREAD_TEST_CASE(test_scoped_config_c) { | ||
BOOST_REQUIRE_MESSAGE( | ||
!config::shard_local_cfg().cluster_id().has_value(), | ||
config::shard_local_cfg().cluster_id()->c_str()); | ||
scoped_config cfg; | ||
cfg.get("cluster_id").set_value(std::make_optional<ss::sstring>("c")); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright 2023 Redpanda Data, Inc. | ||
* | ||
* Use of this software is governed by the Business Source License | ||
* included in the file licenses/BSL.md | ||
* | ||
* As of the Change Date specified in that file, in accordance with | ||
* the Business Source License, use of this software will be governed | ||
* by the Apache License, Version 2.0 | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "config/base_property.h" | ||
#include "config/configuration.h" | ||
|
||
// Scoped wrapper around config::shard_local_cfg() that tracks get() calls and, | ||
// upon destructing, resets any properties that were potentially mutated. | ||
class scoped_config { | ||
public: | ||
~scoped_config() { | ||
for (auto& p : _properties_to_reset) { | ||
config::shard_local_cfg().get(p).reset(); | ||
} | ||
} | ||
|
||
config::base_property& get(std::string_view name) { | ||
_properties_to_reset.emplace_back(name); | ||
return config::shard_local_cfg().get(name); | ||
} | ||
|
||
private: | ||
std::list<ss::sstring> _properties_to_reset; | ||
}; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it has to do this on all shards. Something like:
and same is for setting the value. We have tests which are using more than one shard and setting config parameters (without resetting). For instance
throughput_limits_fixture
in theproduce_consume_test.cc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually the setting part of this seems a bit more involved. I'm not sure it's the right thing to do to always do it on every core. I'm leaning towards forcing test authors to manage this per core with a sharded service or somesuch.