mirror of
https://github.com/mollyim/webrtc.git
synced 2025-05-12 21:30:45 +01:00
Rename test helper for registering field trial keys
This new name emphasizes that the field trial keys are only allowed within the current scope. We already have test::ScopedFieldTrials that can be used to ensure that the global field trials string itself is isolated. Bug: webrtc:14705 Change-Id: I8b66bbd9c11d97985292c334d2d3496a047074a1 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/284862 Commit-Queue: Emil Lundmark <lndmrk@webrtc.org> Reviewed-by: Harald Alvestrand <hta@webrtc.org> Cr-Commit-Position: refs/heads/main@{#38796}
This commit is contained in:
parent
e001474407
commit
2d7a3e7ca8
4 changed files with 22 additions and 19 deletions
|
@ -28,11 +28,11 @@ namespace webrtc {
|
|||
namespace {
|
||||
|
||||
using ::testing::NotNull;
|
||||
using ::webrtc::field_trial::FieldTrialsAllowedInScopeForTesting;
|
||||
using ::webrtc::field_trial::InitFieldTrialsFromString;
|
||||
using ::webrtc::field_trial::ScopedGlobalFieldTrialsForTesting;
|
||||
|
||||
TEST(FieldTrialsTest, EmptyStringHasNoEffect) {
|
||||
ScopedGlobalFieldTrialsForTesting g({"MyCoolTrial"});
|
||||
FieldTrialsAllowedInScopeForTesting k({"MyCoolTrial"});
|
||||
FieldTrials f("");
|
||||
f.RegisterKeysForTesting({"MyCoolTrial"});
|
||||
|
||||
|
@ -53,7 +53,7 @@ TEST(FieldTrialsTest, EnabledDisabledMustBeFirstInValue) {
|
|||
}
|
||||
|
||||
TEST(FieldTrialsTest, FieldTrialsDoesNotReadGlobalString) {
|
||||
ScopedGlobalFieldTrialsForTesting g({"MyCoolTrial", "MyUncoolTrial"});
|
||||
FieldTrialsAllowedInScopeForTesting k({"MyCoolTrial", "MyUncoolTrial"});
|
||||
static constexpr char s[] = "MyCoolTrial/Enabled/MyUncoolTrial/Disabled/";
|
||||
InitFieldTrialsFromString(s);
|
||||
FieldTrials f("");
|
||||
|
@ -64,7 +64,7 @@ TEST(FieldTrialsTest, FieldTrialsDoesNotReadGlobalString) {
|
|||
}
|
||||
|
||||
TEST(FieldTrialsTest, FieldTrialsWritesGlobalString) {
|
||||
ScopedGlobalFieldTrialsForTesting g({"MyCoolTrial", "MyUncoolTrial"});
|
||||
FieldTrialsAllowedInScopeForTesting k({"MyCoolTrial", "MyUncoolTrial"});
|
||||
FieldTrials f("MyCoolTrial/Enabled/MyUncoolTrial/Disabled/");
|
||||
EXPECT_TRUE(webrtc::field_trial::IsEnabled("MyCoolTrial"));
|
||||
EXPECT_TRUE(webrtc::field_trial::IsDisabled("MyUncoolTrial"));
|
||||
|
@ -95,7 +95,7 @@ TEST(FieldTrialsTest, FieldTrialsSupportsSeparateInstances) {
|
|||
}
|
||||
|
||||
TEST(FieldTrialsTest, NonGlobalFieldTrialsInstanceDoesNotModifyGlobalString) {
|
||||
ScopedGlobalFieldTrialsForTesting g({"SomeString"});
|
||||
FieldTrialsAllowedInScopeForTesting k({"SomeString"});
|
||||
std::unique_ptr<FieldTrials> f =
|
||||
FieldTrials::CreateNoGlobal("SomeString/Enabled/");
|
||||
ASSERT_THAT(f, NotNull());
|
||||
|
@ -123,7 +123,7 @@ TEST(FieldTrialsTest, NonGlobalFieldTrialsSupportSimultaneousInstances) {
|
|||
}
|
||||
|
||||
TEST(FieldTrialsTest, GlobalAndNonGlobalFieldTrialsAreDisjoint) {
|
||||
ScopedGlobalFieldTrialsForTesting g({"SomeString", "SomeOtherString"});
|
||||
FieldTrialsAllowedInScopeForTesting k({"SomeString", "SomeOtherString"});
|
||||
FieldTrials f1("SomeString/Enabled/");
|
||||
std::unique_ptr<FieldTrials> f2 =
|
||||
FieldTrials::CreateNoGlobal("SomeOtherString/Enabled/");
|
||||
|
@ -139,7 +139,7 @@ TEST(FieldTrialsTest, GlobalAndNonGlobalFieldTrialsAreDisjoint) {
|
|||
}
|
||||
|
||||
TEST(FieldTrialsTest, FieldTrialBasedConfigReadsGlobalString) {
|
||||
ScopedGlobalFieldTrialsForTesting g({"MyCoolTrial", "MyUncoolTrial"});
|
||||
FieldTrialsAllowedInScopeForTesting k({"MyCoolTrial", "MyUncoolTrial"});
|
||||
static constexpr char s[] = "MyCoolTrial/Enabled/MyUncoolTrial/Disabled/";
|
||||
InitFieldTrialsFromString(s);
|
||||
FieldTrialBasedConfig f;
|
||||
|
|
|
@ -30,17 +30,15 @@ struct DummyExperiment {
|
|||
FieldTrialParameter<std::string> hash =
|
||||
FieldTrialParameter<std::string>("h", "a80");
|
||||
|
||||
field_trial::ScopedGlobalFieldTrialsForTesting g{{kDummyExperiment}};
|
||||
field_trial::FieldTrialsAllowedInScopeForTesting k{{kDummyExperiment}};
|
||||
|
||||
DummyExperiment()
|
||||
: DummyExperiment(field_trial::FindFullName(kDummyExperiment)) {}
|
||||
|
||||
explicit DummyExperiment(absl::string_view field_trial) {
|
||||
ParseFieldTrial({&enabled, &factor, &retries, &size, &ping, &hash},
|
||||
field_trial);
|
||||
}
|
||||
DummyExperiment() {
|
||||
std::string trial_string = field_trial::FindFullName(kDummyExperiment);
|
||||
ParseFieldTrial({&enabled, &factor, &retries, &size, &ping, &hash},
|
||||
trial_string);
|
||||
}
|
||||
};
|
||||
|
||||
enum class CustomEnum {
|
||||
|
|
|
@ -98,11 +98,16 @@ bool FieldTrialsStringIsValid(absl::string_view trials_string);
|
|||
std::string MergeFieldTrialsStrings(absl::string_view first,
|
||||
absl::string_view second);
|
||||
|
||||
// RAII type that ensures global state is consistent between tests.
|
||||
class ScopedGlobalFieldTrialsForTesting {
|
||||
// This helper allows to temporary "register" a field trial within the current
|
||||
// scope. This is only useful for tests that use the global field trial string,
|
||||
// otherwise you can use `webrtc::FieldTrialsRegistry`.
|
||||
//
|
||||
// If you want to isolate changes to the global field trial string itself within
|
||||
// the current scope you should use `webrtc::test::ScopedFieldTrials`.
|
||||
class FieldTrialsAllowedInScopeForTesting {
|
||||
public:
|
||||
explicit ScopedGlobalFieldTrialsForTesting(flat_set<std::string> keys);
|
||||
~ScopedGlobalFieldTrialsForTesting();
|
||||
explicit FieldTrialsAllowedInScopeForTesting(flat_set<std::string> keys);
|
||||
~FieldTrialsAllowedInScopeForTesting();
|
||||
};
|
||||
|
||||
} // namespace field_trial
|
||||
|
|
|
@ -168,12 +168,12 @@ const char* GetFieldTrialString() {
|
|||
return trials_init_string;
|
||||
}
|
||||
|
||||
ScopedGlobalFieldTrialsForTesting::ScopedGlobalFieldTrialsForTesting(
|
||||
FieldTrialsAllowedInScopeForTesting::FieldTrialsAllowedInScopeForTesting(
|
||||
flat_set<std::string> keys) {
|
||||
TestKeys() = std::move(keys);
|
||||
}
|
||||
|
||||
ScopedGlobalFieldTrialsForTesting::~ScopedGlobalFieldTrialsForTesting() {
|
||||
FieldTrialsAllowedInScopeForTesting::~FieldTrialsAllowedInScopeForTesting() {
|
||||
TestKeys().clear();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue