diff options
author | Sara Golemon <sara.golemon@mongodb.com> | 2021-02-01 17:00:59 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-02-10 04:54:37 +0000 |
commit | 92dfc822d41714b47bc20e260aafb54884909acc (patch) | |
tree | 137b627c77938dd87b96b349ef090d9910485104 /src/mongo/transport/message_compressor_manager_test.cpp | |
parent | d7b4c6bcaa61dc54d830007657babdd6337f9cfb (diff) | |
download | mongo-92dfc822d41714b47bc20e260aafb54884909acc.tar.gz |
SERVER-53150 Specify input/output to hello command
Diffstat (limited to 'src/mongo/transport/message_compressor_manager_test.cpp')
-rw-r--r-- | src/mongo/transport/message_compressor_manager_test.cpp | 41 |
1 files changed, 31 insertions, 10 deletions
diff --git a/src/mongo/transport/message_compressor_manager_test.cpp b/src/mongo/transport/message_compressor_manager_test.cpp index 979e75d0842..24cff651933 100644 --- a/src/mongo/transport/message_compressor_manager_test.cpp +++ b/src/mongo/transport/message_compressor_manager_test.cpp @@ -85,7 +85,8 @@ void checkNegotiationResult(const BSONObj& result, const std::vector<std::string } } -void checkServerNegotiation(const BSONObj& input, const std::vector<std::string>& expected) { +void checkServerNegotiation(const boost::optional<std::vector<StringData>>& input, + const std::vector<std::string>& expected) { auto registry = buildRegistry(); MessageCompressorManager manager(®istry); @@ -105,8 +106,8 @@ void checkFidelity(const Message& msg, std::unique_ptr<MessageCompressorBase> co registry.finalizeSupportedCompressors().transitional_ignore(); MessageCompressorManager mgr(®istry); - auto negotiator = BSON("isMaster" << 1 << "compression" << BSON_ARRAY(compressorName)); BSONObjBuilder negotiatorOut; + std::vector<StringData> negotiator({compressorName}); mgr.serverNegotiate(negotiator, &negotiatorOut); checkNegotiationResult(negotiatorOut.done(), {compressorName}); @@ -182,26 +183,46 @@ Message buildMessage() { TEST(MessageCompressorManager, NoCompressionRequested) { auto input = BSON("isMaster" << 1); - checkServerNegotiation(input, {}); + checkServerNegotiation(boost::none, {}); } TEST(MessageCompressorManager, NormalCompressionRequested) { - auto input = BSON("isMaster" << 1 << "compression" << BSON_ARRAY("noop")); + std::vector<StringData> input{"noop"_sd}; checkServerNegotiation(input, {"noop"}); } TEST(MessageCompressorManager, BadCompressionRequested) { - auto input = BSON("isMaster" << 1 << "compression" << BSON_ARRAY("fakecompressor")); + std::vector<StringData> input{"fakecompressor"_sd}; checkServerNegotiation(input, {}); } TEST(MessageCompressorManager, BadAndGoodCompressionRequested) { - auto input = BSON("isMaster" << 1 << "compression" - << BSON_ARRAY("fakecompressor" - << "noop")); + std::vector<StringData> input{"fakecompressor"_sd, "noop"_sd}; checkServerNegotiation(input, {"noop"}); } +// Transitional: Parse BSON "isMaster"-like docs for compressor lists. +boost::optional<std::vector<StringData>> parseBSON(BSONObj input) { + auto elem = input["compression"]; + if (!elem) { + return boost::none; + } + + uassert(ErrorCodes::BadValue, + str::stream() << "'compression' is not an array: " << elem, + elem.type() == Array); + + std::vector<StringData> ret; + for (const auto& e : elem.Obj()) { + uassert(ErrorCodes::BadValue, + str::stream() << "'compression' element is not a string: " << e, + e.type() == String); + ret.push_back(e.valueStringData()); + } + + return ret; +} + TEST(MessageCompressorManager, FullNormalCompression) { auto registry = buildRegistry(); MessageCompressorManager clientManager(®istry); @@ -213,7 +234,7 @@ TEST(MessageCompressorManager, FullNormalCompression) { checkNegotiationResult(clientObj, {"noop"}); BSONObjBuilder serverOutput; - serverManager.serverNegotiate(clientObj, &serverOutput); + serverManager.serverNegotiate(parseBSON(clientObj), &serverOutput); auto serverObj = serverOutput.done(); checkNegotiationResult(serverObj, {"noop"}); @@ -285,7 +306,7 @@ TEST(MessageCompressorManager, SERVER_28008) { clientManager.clientBegin(&clientOutput); auto clientObj = clientOutput.done(); BSONObjBuilder serverOutput; - serverManager.serverNegotiate(clientObj, &serverOutput); + serverManager.serverNegotiate(parseBSON(clientObj), &serverOutput); auto serverObj = serverOutput.done(); clientManager.clientFinish(serverObj); |