diff options
author | Hugh Tong <hugh.tong@mongodb.com> | 2023-05-15 15:28:20 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2023-05-15 18:00:33 +0000 |
commit | b45d9b1215bedf4328bded55913475dd6b589e92 (patch) | |
tree | ae2f4299360c4b930fef4935535a95b99fb2e002 /src/mongo/db/curop_test.cpp | |
parent | f1ac91d1e2db63009bd9f41d068f09f009c024cf (diff) | |
download | mongo-b45d9b1215bedf4328bded55913475dd6b589e92.tar.gz |
SERVER-76634 Add SerializationContext object to ExpressionContext
Diffstat (limited to 'src/mongo/db/curop_test.cpp')
-rw-r--r-- | src/mongo/db/curop_test.cpp | 43 |
1 files changed, 42 insertions, 1 deletions
diff --git a/src/mongo/db/curop_test.cpp b/src/mongo/db/curop_test.cpp index c5d2d7947ca..8a737f1a748 100644 --- a/src/mongo/db/curop_test.cpp +++ b/src/mongo/db/curop_test.cpp @@ -32,6 +32,7 @@ #include "mongo/bson/bsonobjbuilder.h" #include "mongo/db/curop.h" #include "mongo/db/query/query_test_service_context.h" +#include "mongo/idl/server_parameter_test_util.h" #include "mongo/unittest/unittest.h" #include "mongo/util/tick_source_mock.h" @@ -269,7 +270,7 @@ TEST(CurOpTest, ShouldNotReportFailpointMsgIfNotSet) { BSONObjBuilder reportedStateWithoutFailpointMsg; { stdx::lock_guard<Client> lk(*opCtx->getClient()); - curop->reportState(&reportedStateWithoutFailpointMsg); + curop->reportState(&reportedStateWithoutFailpointMsg, SerializationContext()); } auto bsonObj = reportedStateWithoutFailpointMsg.done(); @@ -304,5 +305,45 @@ TEST(CurOpTest, ElapsedTimeReflectsTickSource) { ASSERT_EQ(Milliseconds{20}, duration_cast<Milliseconds>(curop->elapsedTimeTotal())); } +TEST(CurOpTest, CheckNSAgainstSerializationContext) { + RAIIServerParameterControllerForTest multitenanyController("multitenancySupport", true); + TenantId tid = TenantId(OID::gen()); + + QueryTestServiceContext serviceContext; + auto opCtx = serviceContext.makeOperationContext(); + + auto curop = CurOp::get(*opCtx); + + // Create dummy command. + BSONObj command = BSON("a" << 3); + + // Set dummy 'ns' and 'command'. + curop->setGenericOpRequestDetails( + NamespaceString::createNamespaceString_forTest(tid, "testDb.coll"), + nullptr, + command, + NetworkOp::dbQuery); + + // Test without using the expectPrefix field. + // TODO SERVER-74284: uncomment the below and remove the line after when command + // serializer/deserializer is plumbed in + // for (bool tenantIdFromDollarTenantOrSecurityToken : {false, true}) { + bool tenantIdFromDollarTenantOrSecurityToken = false; + + SerializationContext sc = SerializationContext::stateCommandRequest(); + sc.setTenantIdSource(tenantIdFromDollarTenantOrSecurityToken); + + BSONObjBuilder builder; + { + stdx::lock_guard<Client> lk(*opCtx->getClient()); + curop->reportState(&builder, sc); + } + auto bsonObj = builder.done(); + + std::string serializedNs = + tenantIdFromDollarTenantOrSecurityToken ? "testDb.coll" : tid.toString() + "_testDb.coll"; + ASSERT_EQ(serializedNs, bsonObj.getField("ns").String()); + // } +} } // namespace } // namespace mongo |