diff options
Diffstat (limited to 'src/mongo/dbtests')
-rw-r--r-- | src/mongo/dbtests/extensions_callback_real_test.cpp | 73 | ||||
-rw-r--r-- | src/mongo/dbtests/matchertests.cpp | 4 | ||||
-rw-r--r-- | src/mongo/dbtests/query_stage_collscan.cpp | 2 | ||||
-rw-r--r-- | src/mongo/dbtests/query_stage_count.cpp | 3 | ||||
-rw-r--r-- | src/mongo/dbtests/query_stage_ensure_sorted.cpp | 7 | ||||
-rw-r--r-- | src/mongo/dbtests/query_stage_fetch.cpp | 2 | ||||
-rw-r--r-- | src/mongo/dbtests/query_stage_multiplan.cpp | 3 | ||||
-rw-r--r-- | src/mongo/dbtests/query_stage_sort.cpp | 3 | ||||
-rw-r--r-- | src/mongo/dbtests/query_stage_sort_key_generator.cpp | 8 | ||||
-rw-r--r-- | src/mongo/dbtests/query_stage_tests.cpp | 2 | ||||
-rw-r--r-- | src/mongo/dbtests/query_stage_update.cpp | 8 |
11 files changed, 39 insertions, 76 deletions
diff --git a/src/mongo/dbtests/extensions_callback_real_test.cpp b/src/mongo/dbtests/extensions_callback_real_test.cpp index bdc84eb61bd..ae2287ac77a 100644 --- a/src/mongo/dbtests/extensions_callback_real_test.cpp +++ b/src/mongo/dbtests/extensions_callback_real_test.cpp @@ -240,72 +240,23 @@ TEST_F(ExtensionsCallbackRealTest, TextDiacriticSensitiveAndCaseSensitiveTrue) { // // $where parsing tests. // +const NamespaceString kTestNss = NamespaceString("db.dummy"); -TEST_F(ExtensionsCallbackRealTest, WhereExpressionsWithSameScopeHaveSameBSONRepresentation) { - const char code[] = "function(){ return a; }"; +TEST_F(ExtensionsCallbackRealTest, WhereExpressionDesugarsToExprAndInternalJs) { + auto query1 = fromjson("{$where: 'function() { return this.x == 10; }'}"); + boost::intrusive_ptr<ExpressionContext> expCtx( + new ExpressionContext(&_opCtx, nullptr, kTestNss)); - BSONObj query1 = BSON("$where" << BSONCodeWScope(code, BSON("a" << true))); auto expr1 = unittest::assertGet( - ExtensionsCallbackReal(&_opCtx, &_nss).parseWhere(query1.firstElement())); - BSONObjBuilder builder1; - expr1->serialize(&builder1); + ExtensionsCallbackReal(&_opCtx, &_nss).parseWhere(expCtx, query1.firstElement())); - BSONObj query2 = BSON("$where" << BSONCodeWScope(code, BSON("a" << true))); - auto expr2 = unittest::assertGet( - ExtensionsCallbackReal(&_opCtx, &_nss).parseWhere(query2.firstElement())); - BSONObjBuilder builder2; - expr2->serialize(&builder2); + BSONObjBuilder gotMatch; + expr1->serialize(&gotMatch); - ASSERT_BSONOBJ_EQ(builder1.obj(), builder2.obj()); -} - -TEST_F(ExtensionsCallbackRealTest, - WhereExpressionsWithDifferentScopesHaveDifferentBSONRepresentations) { - const char code[] = "function(){ return a; }"; - - BSONObj query1 = BSON("$where" << BSONCodeWScope(code, BSON("a" << true))); - auto expr1 = unittest::assertGet( - ExtensionsCallbackReal(&_opCtx, &_nss).parseWhere(query1.firstElement())); - BSONObjBuilder builder1; - expr1->serialize(&builder1); - - BSONObj query2 = BSON("$where" << BSONCodeWScope(code, BSON("a" << false))); - auto expr2 = unittest::assertGet( - ExtensionsCallbackReal(&_opCtx, &_nss).parseWhere(query2.firstElement())); - BSONObjBuilder builder2; - expr2->serialize(&builder2); - - ASSERT_BSONOBJ_NE(builder1.obj(), builder2.obj()); -} - -TEST_F(ExtensionsCallbackRealTest, WhereExpressionsWithSameScopeAreEquivalent) { - const char code[] = "function(){ return a; }"; - - BSONObj query1 = BSON("$where" << BSONCodeWScope(code, BSON("a" << true))); - auto expr1 = unittest::assertGet( - ExtensionsCallbackReal(&_opCtx, &_nss).parseWhere(query1.firstElement())); - - BSONObj query2 = BSON("$where" << BSONCodeWScope(code, BSON("a" << true))); - auto expr2 = unittest::assertGet( - ExtensionsCallbackReal(&_opCtx, &_nss).parseWhere(query2.firstElement())); - - ASSERT(expr1->equivalent(expr2.get())); - ASSERT(expr2->equivalent(expr1.get())); -} - -TEST_F(ExtensionsCallbackRealTest, WhereExpressionsWithDifferentScopesAreNotEquivalent) { - const char code[] = "function(){ return a; }"; - - BSONObj query1 = BSON("$where" << BSONCodeWScope(code, BSON("a" << true))); - auto expr1 = unittest::assertGet( - ExtensionsCallbackReal(&_opCtx, &_nss).parseWhere(query1.firstElement())); - - BSONObj query2 = BSON("$where" << BSONCodeWScope(code, BSON("a" << false))); - auto expr2 = unittest::assertGet( - ExtensionsCallbackReal(&_opCtx, &_nss).parseWhere(query2.firstElement())); - - ASSERT_FALSE(expr1->equivalent(expr2.get())); - ASSERT_FALSE(expr2->equivalent(expr1.get())); + auto expectedMatch = fromjson( + "{$expr: {$function: {'body': 'function() { return this.x == 10; }', 'args': " + "['$$CURRENT'], 'lang': 'js', '_internalSetObjToThis': true}}}"); + ASSERT_BSONOBJ_EQ(gotMatch.obj(), expectedMatch); } } // namespace diff --git a/src/mongo/dbtests/matchertests.cpp b/src/mongo/dbtests/matchertests.cpp index b0fb98ded31..bc3e329816c 100644 --- a/src/mongo/dbtests/matchertests.cpp +++ b/src/mongo/dbtests/matchertests.cpp @@ -54,6 +54,8 @@ public: virtual ~CollectionBase() {} }; +const NamespaceString kTestNss = NamespaceString("db.dummy"); + template <typename M> class Basic { public: @@ -229,7 +231,7 @@ public: const CollatorInterface* collator = nullptr; const boost::intrusive_ptr<ExpressionContext> expCtx( - new ExpressionContext(opCtxPtr.get(), collator)); + new ExpressionContext(opCtxPtr.get(), collator, kTestNss)); M m(BSON("$where" << "function(){ return this.a == 1; }"), expCtx, diff --git a/src/mongo/dbtests/query_stage_collscan.cpp b/src/mongo/dbtests/query_stage_collscan.cpp index 757bb50c393..5eb79bb6e80 100644 --- a/src/mongo/dbtests/query_stage_collscan.cpp +++ b/src/mongo/dbtests/query_stage_collscan.cpp @@ -96,7 +96,7 @@ public: // Make the filter. const CollatorInterface* collator = nullptr; const boost::intrusive_ptr<ExpressionContext> expCtx( - new ExpressionContext(&_opCtx, collator)); + new ExpressionContext(&_opCtx, collator, nss)); StatusWithMatchExpression statusWithMatcher = MatchExpressionParser::parse(filterObj, expCtx); verify(statusWithMatcher.isOK()); diff --git a/src/mongo/dbtests/query_stage_count.cpp b/src/mongo/dbtests/query_stage_count.cpp index e8bdc4a0dba..0c62e6636f4 100644 --- a/src/mongo/dbtests/query_stage_count.cpp +++ b/src/mongo/dbtests/query_stage_count.cpp @@ -53,6 +53,7 @@ using std::vector; const int kDocuments = 100; const int kInterjections = kDocuments; +const NamespaceString kTestNss = NamespaceString("db.dummy"); class CountStageTest { public: @@ -147,7 +148,7 @@ public: const CollatorInterface* collator = nullptr; const boost::intrusive_ptr<ExpressionContext> expCtx( - new ExpressionContext(&_opCtx, collator)); + new ExpressionContext(&_opCtx, collator, kTestNss)); StatusWithMatchExpression statusWithMatcher = MatchExpressionParser::parse(request.getQuery(), expCtx); ASSERT(statusWithMatcher.isOK()); diff --git a/src/mongo/dbtests/query_stage_ensure_sorted.cpp b/src/mongo/dbtests/query_stage_ensure_sorted.cpp index a3a81a84660..e956472d40d 100644 --- a/src/mongo/dbtests/query_stage_ensure_sorted.cpp +++ b/src/mongo/dbtests/query_stage_ensure_sorted.cpp @@ -43,6 +43,8 @@ namespace mongo { namespace { +const NamespaceString kTestNss = NamespaceString("db.dummy"); + class QueryStageEnsureSortedTest : public unittest::Test { public: /** @@ -80,7 +82,7 @@ public: // Create a mock ExpressionContext. boost::intrusive_ptr<ExpressionContext> pExpCtx( - new ExpressionContext(opCtx.get(), collator)); + new ExpressionContext(opCtx.get(), collator, kTestNss)); pExpCtx->setCollator(collator); // Initialization. @@ -121,7 +123,8 @@ TEST_F(QueryStageEnsureSortedTest, EnsureSortedEmptyWorkingSet) { auto opCtx = _serviceContext.makeOperationContext(); // Create a mock ExpressionContext. - boost::intrusive_ptr<ExpressionContext> pExpCtx(new ExpressionContext(opCtx.get(), nullptr)); + boost::intrusive_ptr<ExpressionContext> pExpCtx( + new ExpressionContext(opCtx.get(), nullptr, kTestNss)); WorkingSet ws; auto queuedDataStage = std::make_unique<QueuedDataStage>(opCtx.get(), &ws); diff --git a/src/mongo/dbtests/query_stage_fetch.cpp b/src/mongo/dbtests/query_stage_fetch.cpp index 13781d15b3a..53b4e1e0646 100644 --- a/src/mongo/dbtests/query_stage_fetch.cpp +++ b/src/mongo/dbtests/query_stage_fetch.cpp @@ -202,7 +202,7 @@ public: BSONObj filterObj = BSON("foo" << 6); const CollatorInterface* collator = nullptr; const boost::intrusive_ptr<ExpressionContext> expCtx( - new ExpressionContext(&_opCtx, collator)); + new ExpressionContext(&_opCtx, collator, nss())); StatusWithMatchExpression statusWithMatcher = MatchExpressionParser::parse(filterObj, expCtx); verify(statusWithMatcher.isOK()); diff --git a/src/mongo/dbtests/query_stage_multiplan.cpp b/src/mongo/dbtests/query_stage_multiplan.cpp index 23e624a0465..a9b5a8375fe 100644 --- a/src/mongo/dbtests/query_stage_multiplan.cpp +++ b/src/mongo/dbtests/query_stage_multiplan.cpp @@ -155,7 +155,8 @@ unique_ptr<PlanStage> getIxScanPlan(OperationContext* opCtx, unique_ptr<MatchExpression> makeMatchExpressionFromFilter(OperationContext* opCtx, BSONObj filterObj) { const CollatorInterface* collator = nullptr; - const boost::intrusive_ptr<ExpressionContext> expCtx(new ExpressionContext(opCtx, collator)); + const boost::intrusive_ptr<ExpressionContext> expCtx( + new ExpressionContext(opCtx, collator, nss)); StatusWithMatchExpression statusWithMatcher = MatchExpressionParser::parse(filterObj, expCtx); ASSERT_OK(statusWithMatcher.getStatus()); unique_ptr<MatchExpression> filter = std::move(statusWithMatcher.getValue()); diff --git a/src/mongo/dbtests/query_stage_sort.cpp b/src/mongo/dbtests/query_stage_sort.cpp index 9f521d7fc36..3e01a3c97f6 100644 --- a/src/mongo/dbtests/query_stage_sort.cpp +++ b/src/mongo/dbtests/query_stage_sort.cpp @@ -236,7 +236,8 @@ public: protected: const ServiceContext::UniqueOperationContext _txnPtr = cc().makeOperationContext(); OperationContext& _opCtx = *_txnPtr; - boost::intrusive_ptr<ExpressionContext> _expCtx = new ExpressionContext(&_opCtx, nullptr); + boost::intrusive_ptr<ExpressionContext> _expCtx = + new ExpressionContext(&_opCtx, nullptr, nss()); DBDirectClient _client; }; diff --git a/src/mongo/dbtests/query_stage_sort_key_generator.cpp b/src/mongo/dbtests/query_stage_sort_key_generator.cpp index fe7ae6583c0..351ad1cca0c 100644 --- a/src/mongo/dbtests/query_stage_sort_key_generator.cpp +++ b/src/mongo/dbtests/query_stage_sort_key_generator.cpp @@ -55,6 +55,8 @@ Value extractKeyFromKeyGenStage(SortKeyGeneratorStage* sortKeyGen, WorkingSet* w return wsm->metadata().getSortKey(); } +const NamespaceString kTestNss = NamespaceString("db.dummy"); + /** * Given a JSON string 'sortSpec' representing a sort pattern, returns the corresponding sort key * from 'doc', a JSON string representation of a user document. Does so using the SORT_KEY_GENERATOR @@ -66,7 +68,8 @@ Value extractKeyFromKeyGenStage(SortKeyGeneratorStage* sortKeyGen, WorkingSet* w Value extractSortKey(const char* sortSpec, const char* doc, const CollatorInterface* collator) { QueryTestServiceContext serviceContext; auto opCtx = serviceContext.makeOperationContext(); - boost::intrusive_ptr<ExpressionContext> pExpCtx(new ExpressionContext(opCtx.get(), collator)); + boost::intrusive_ptr<ExpressionContext> pExpCtx( + new ExpressionContext(opCtx.get(), collator, kTestNss)); WorkingSet workingSet; @@ -95,7 +98,8 @@ Value extractSortKeyCovered(const char* sortSpec, const CollatorInterface* collator) { QueryTestServiceContext serviceContext; auto opCtx = serviceContext.makeOperationContext(); - boost::intrusive_ptr<ExpressionContext> pExpCtx(new ExpressionContext(opCtx.get(), collator)); + boost::intrusive_ptr<ExpressionContext> pExpCtx( + new ExpressionContext(opCtx.get(), collator, kTestNss)); WorkingSet workingSet; diff --git a/src/mongo/dbtests/query_stage_tests.cpp b/src/mongo/dbtests/query_stage_tests.cpp index a81bee3b634..43a6c482131 100644 --- a/src/mongo/dbtests/query_stage_tests.cpp +++ b/src/mongo/dbtests/query_stage_tests.cpp @@ -85,7 +85,7 @@ public: const CollatorInterface* collator = nullptr; const boost::intrusive_ptr<ExpressionContext> expCtx( - new ExpressionContext(&_opCtx, collator)); + new ExpressionContext(&_opCtx, collator, NamespaceString(ns()))); StatusWithMatchExpression statusWithMatcher = MatchExpressionParser::parse(filterObj, expCtx); verify(statusWithMatcher.isOK()); diff --git a/src/mongo/dbtests/query_stage_update.cpp b/src/mongo/dbtests/query_stage_update.cpp index 2f501af6690..98061f09523 100644 --- a/src/mongo/dbtests/query_stage_update.cpp +++ b/src/mongo/dbtests/query_stage_update.cpp @@ -201,7 +201,7 @@ public: CurOp& curOp = *CurOp::get(_opCtx); OpDebug* opDebug = &curOp.debug(); const CollatorInterface* collator = nullptr; - UpdateDriver driver(new ExpressionContext(&_opCtx, collator)); + UpdateDriver driver(new ExpressionContext(&_opCtx, collator, nss)); Collection* collection = ctx.getCollection(); ASSERT(collection); @@ -272,7 +272,7 @@ public: CurOp& curOp = *CurOp::get(_opCtx); OpDebug* opDebug = &curOp.debug(); const CollatorInterface* collator = nullptr; - UpdateDriver driver(new ExpressionContext(&_opCtx, collator)); + UpdateDriver driver(new ExpressionContext(&_opCtx, collator, nss)); Collection* coll = CollectionCatalog::get(&_opCtx).lookupCollectionByNamespace(&_opCtx, nss); ASSERT(coll); @@ -387,7 +387,7 @@ public: ASSERT(coll); UpdateRequest request(nss); const CollatorInterface* collator = nullptr; - UpdateDriver driver(new ExpressionContext(&_opCtx, collator)); + UpdateDriver driver(new ExpressionContext(&_opCtx, collator, nss)); const int targetDocIndex = 0; // We'll be working with the first doc in the collection. const BSONObj query = BSON("foo" << BSON("$gte" << targetDocIndex)); const auto ws = make_unique<WorkingSet>(); @@ -479,7 +479,7 @@ public: ASSERT(coll); UpdateRequest request(nss); const CollatorInterface* collator = nullptr; - UpdateDriver driver(new ExpressionContext(&_opCtx, collator)); + UpdateDriver driver(new ExpressionContext(&_opCtx, collator, nss)); const int targetDocIndex = 10; const BSONObj query = BSON("foo" << BSON("$gte" << targetDocIndex)); const auto ws = make_unique<WorkingSet>(); |