diff options
author | Ian Boros <ian.boros@10gen.com> | 2018-07-27 16:08:02 -0400 |
---|---|---|
committer | Ian Boros <ian.boros@10gen.com> | 2018-07-27 18:22:18 -0400 |
commit | baecc1ad1893c1502f316cc18d2439fb225d9dcd (patch) | |
tree | e5fdab44b39fdcca3d2a7e76671c2eff636591e2 /src/mongo/db/catalog/index_key_validate_test.cpp | |
parent | b42420caf1018835da58ace37b51099931b904c0 (diff) | |
download | mongo-baecc1ad1893c1502f316cc18d2439fb225d9dcd.tar.gz |
SERVER-36199 Put allPaths index creation behind a query knob
Diffstat (limited to 'src/mongo/db/catalog/index_key_validate_test.cpp')
-rw-r--r-- | src/mongo/db/catalog/index_key_validate_test.cpp | 58 |
1 files changed, 34 insertions, 24 deletions
diff --git a/src/mongo/db/catalog/index_key_validate_test.cpp b/src/mongo/db/catalog/index_key_validate_test.cpp index cc8978d0673..1d170fbbde7 100644 --- a/src/mongo/db/catalog/index_key_validate_test.cpp +++ b/src/mongo/db/catalog/index_key_validate_test.cpp @@ -36,6 +36,7 @@ #include "mongo/bson/bsonmisc.h" #include "mongo/bson/bsonobjbuilder.h" #include "mongo/db/index/index_descriptor.h" +#include "mongo/db/query/query_knobs.h" #include "mongo/unittest/unittest.h" namespace mongo { @@ -45,6 +46,31 @@ namespace { using IndexVersion = IndexDescriptor::IndexVersion; using index_key_validate::validateKeyPattern; +/** + * Helper class to ensure proper FCV & test commands enabled. + * TODO: Remove test command enabling/disabling in SERVER-36198 + */ +class TestCommandQueryKnobGuard { + +public: + TestCommandQueryKnobGuard() { + _prevEnabled = getTestCommandsEnabled(); + setTestCommandsEnabled(true); + + _prevKnobEnabled = internalQueryAllowAllPathsIndexes.load(); + internalQueryAllowAllPathsIndexes.store(true); + } + + ~TestCommandQueryKnobGuard() { + setTestCommandsEnabled(_prevEnabled); + internalQueryAllowAllPathsIndexes.store(_prevKnobEnabled); + } + +private: + bool _prevEnabled; + bool _prevKnobEnabled; +}; + TEST(IndexKeyValidateTest, KeyElementValueOfSmallPositiveIntSucceeds) { for (auto indexVersion : IndexDescriptor::getSupportedIndexVersions()) { ASSERT_OK(validateKeyPattern(BSON("x" << 1), indexVersion)); @@ -237,77 +263,61 @@ TEST(IndexKeyValidateTest, KeyElementNameTextSucceedsOnTextIndex) { } TEST(IndexKeyValidateTest, KeyElementNameAllPathsSucceedsOnSubPath) { - const bool temp = getTestCommandsEnabled(); - setTestCommandsEnabled(true); + TestCommandQueryKnobGuard guard; ASSERT_OK(validateKeyPattern(BSON("a.$**" << 1), IndexVersion::kV2)); - setTestCommandsEnabled(temp); } TEST(IndexKeyValidateTest, KeyElementNameAllPathsSucceeds) { - const bool temp = getTestCommandsEnabled(); - setTestCommandsEnabled(true); + TestCommandQueryKnobGuard guard; ASSERT_OK(validateKeyPattern(BSON("$**" << 1), IndexVersion::kV2)); - setTestCommandsEnabled(temp); } TEST(IndexKeyValidateTest, KeyElementNameAllPathsFailsOnRepeat) { - const bool temp = getTestCommandsEnabled(); - setTestCommandsEnabled(true); + TestCommandQueryKnobGuard guard; auto status = validateKeyPattern(BSON("$**.$**" << 1), IndexVersion::kV2); ASSERT_NOT_OK(status); ASSERT_EQ(status, ErrorCodes::CannotCreateIndex); - setTestCommandsEnabled(temp); } TEST(IndexKeyValidateTest, KeyElementNameAllPathsFailsOnSubPathRepeat) { - const bool temp = getTestCommandsEnabled(); - setTestCommandsEnabled(true); + TestCommandQueryKnobGuard guard; auto status = validateKeyPattern(BSON("a.$**.$**" << 1), IndexVersion::kV2); ASSERT_NOT_OK(status); ASSERT_EQ(status, ErrorCodes::CannotCreateIndex); - setTestCommandsEnabled(temp); } TEST(IndexKeyValidateTest, KeyElementNameAllPathsFailsOnCompound) { - const bool temp = getTestCommandsEnabled(); - setTestCommandsEnabled(true); + TestCommandQueryKnobGuard guard; auto status = validateKeyPattern(BSON("$**" << 1 << "a" << 1), IndexVersion::kV2); ASSERT_NOT_OK(status); ASSERT_EQ(status, ErrorCodes::CannotCreateIndex); - setTestCommandsEnabled(temp); } TEST(IndexKeyValidateTest, KeyElementNameAllPathsFailsOnIncorrectValue) { - const bool temp = getTestCommandsEnabled(); - setTestCommandsEnabled(true); + TestCommandQueryKnobGuard guard; auto status = validateKeyPattern(BSON("$**" << false), IndexVersion::kV2); ASSERT_NOT_OK(status); ASSERT_EQ(status, ErrorCodes::CannotCreateIndex); - setTestCommandsEnabled(temp); } TEST(IndexKeyValidateTest, KeyElementNameAllPathsFailsWhenValueIsPluginNameWithInvalidKeyName) { // TODO: Remove test command enabling/disabling in SERVER-36198 - const bool temp = getTestCommandsEnabled(); - setTestCommandsEnabled(true); + TestCommandQueryKnobGuard guard; auto status = validateKeyPattern(BSON("a" << "allPaths"), IndexVersion::kV2); ASSERT_NOT_OK(status); ASSERT_EQ(status, ErrorCodes::CannotCreateIndex); - setTestCommandsEnabled(temp); } TEST(IndexKeyValidateTest, KeyElementNameAllPathsFailsWhenValueIsPluginNameWithValidKeyName) { // TODO: Remove test command enabling/disabling in SERVER-36198 - const bool temp = getTestCommandsEnabled(); - setTestCommandsEnabled(true); + TestCommandQueryKnobGuard guard; auto status = validateKeyPattern(BSON("$**" << "allPaths"), IndexVersion::kV2); ASSERT_NOT_OK(status); ASSERT_EQ(status, ErrorCodes::CannotCreateIndex); - setTestCommandsEnabled(temp); } } // namespace |