[SERVER-23585] CanonicalQuery doesn't outlive QuerySolutions in QueryPlannerTest fixture Created: 06/Apr/16  Updated: 21/Nov/16  Resolved: 09/Apr/16

Status: Closed
Project: Core Server
Component/s: Querying
Affects Version/s: 3.1.6
Fix Version/s: 3.2.7, 3.3.5

Type: Bug Priority: Major - P3
Reporter: Max Hirschhorn Assignee: Max Hirschhorn
Resolution: Done Votes: 0
Labels: test-only
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: Text File asan_output.log    
Backwards Compatibility: Fully Compatible
Operating System: ALL
Backport Completed:
Steps To Reproduce:

Apply the following patch and run the query_planner_geo_test C++ unit test under ASan.

diff --git a/src/mongo/db/matcher/expression_geo.h b/src/mongo/db/matcher/expression_geo.h
index 856b310..5631e2e 100644
--- a/src/mongo/db/matcher/expression_geo.h
+++ b/src/mongo/db/matcher/expression_geo.h
@@ -151,7 +151,7 @@ public:
 
     std::string toString() const {
         std::stringstream ss;
-        ss << " field=" << field;
+        // ss << " field=" << field;
         ss << " maxdist=" << maxDistance;
         ss << " isNearSphere=" << isNearSphere;
         return ss.str();
diff --git a/src/mongo/db/query/query_planner_test_fixture.cpp b/src/mongo/db/query/query_planner_test_fixture.cpp
index 15ecad4..5725bd0 100644
--- a/src/mongo/db/query/query_planner_test_fixture.cpp
+++ b/src/mongo/db/query/query_planner_test_fixture.cpp
@@ -315,13 +315,14 @@ void QueryPlannerTest::dumpSolutions(mongoutils::str::stream& ost) const {
 }
 
 void QueryPlannerTest::assertNumSolutions(size_t expectSolutions) const {
-    if (getNumSolutions() == expectSolutions) {
-        return;
-    }
     mongoutils::str::stream ss;
     ss << "expected " << expectSolutions << " solutions but got " << getNumSolutions()
        << " instead. solutions generated: " << '\n';
     dumpSolutions(ss);
+    log() << static_cast<std::string>(ss);
+    if (getNumSolutions() == expectSolutions) {
+        return;
+    }
     FAIL(ss);
 }

Sprint: Query 13 (04/22/16)
Participants:

 Description   

The CanonicalQuery is deleted when statusWithCQ goes out of scope in QueryPlannerTest::runInvalidQueryFull(). This was introduced by the changes from SERVER-16889.

void QueryPlannerTest::runInvalidQueryFull(const BSONObj& query,
                                           const BSONObj& sort,
                                           const BSONObj& proj,
                                           long long skip,
                                           long long limit,
                                           const BSONObj& hint,
                                           const BSONObj& minObj,
                                           const BSONObj& maxObj,
                                           bool snapshot) {
    solns.clear();
 
    auto statusWithCQ = CanonicalQuery::canonicalize(nss,
                                                     query,
                                                     sort,
                                                     proj,
                                                     skip,
                                                     limit,
                                                     hint,
                                                     minObj,
                                                     maxObj,
                                                     snapshot,
                                                     false,  // explain
                                                     ExtensionsCallbackNoop());
    ASSERT_OK(statusWithCQ.getStatus());
 
    Status s = QueryPlanner::plan(*statusWithCQ.getValue(), params, &solns.mutableVector());
    ASSERT_NOT_OK(s);
}



 Comments   
Comment by Githook User [ 24/May/16 ]

Author:

{u'username': u'visemet', u'name': u'Max Hirschhorn', u'email': u'max.hirschhorn@mongodb.com'}

Message: SERVER-23585 Make CanonicalQuery outlive QuerySolutions in unit tests.

(cherry picked from commit f29ac715bf245cfc7f28718b6c1c24521439b22d)
Branch: v3.2
https://github.com/mongodb/mongo/commit/c050da29fc33c19463e0b239bbcda3c0c001ea94

Comment by Githook User [ 09/Apr/16 ]

Author:

{u'username': u'visemet', u'name': u'Max Hirschhorn', u'email': u'max.hirschhorn@mongodb.com'}

Message: SERVER-23585 Make CanonicalQuery outlive QuerySolutions in unit tests.
Branch: master
https://github.com/mongodb/mongo/commit/f29ac715bf245cfc7f28718b6c1c24521439b22d

Generated at Thu Feb 08 04:03:49 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.