summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsamantharitter <samantha.ritter@10gen.com>2017-10-10 10:27:25 -0400
committerKaloian Manassiev <kaloian.manassiev@mongodb.com>2017-10-10 14:50:19 -0400
commitdb00a0d9b5045f609c1dc2647ed6ebe1bd2a339f (patch)
tree3d161a98f10bd123656cfe1e4c2e47c1020220b6
parentce1158916cfea26a6072d7867199ee150f90b6fa (diff)
downloadmongo-db00a0d9b5045f609c1dc2647ed6ebe1bd2a339f.tar.gz
SERVER-31184 Make EnsureFCV a separate test utility
-rw-r--r--src/mongo/db/pipeline/document_source_change_stream_test.cpp18
-rw-r--r--src/mongo/db/pipeline/pipeline_test.cpp32
-rw-r--r--src/mongo/db/repl/oplog_fetcher_test.cpp17
-rw-r--r--src/mongo/unittest/ensure_fcv.h56
4 files changed, 68 insertions, 55 deletions
diff --git a/src/mongo/db/pipeline/document_source_change_stream_test.cpp b/src/mongo/db/pipeline/document_source_change_stream_test.cpp
index 9f5b1f5844e..7682972c787 100644
--- a/src/mongo/db/pipeline/document_source_change_stream_test.cpp
+++ b/src/mongo/db/pipeline/document_source_change_stream_test.cpp
@@ -46,6 +46,7 @@
#include "mongo/db/pipeline/value_comparator.h"
#include "mongo/db/repl/oplog_entry.h"
#include "mongo/db/repl/replication_coordinator_mock.h"
+#include "mongo/unittest/ensure_fcv.h"
#include "mongo/unittest/unittest.h"
#include "mongo/util/uuid.h"
@@ -64,25 +65,12 @@ using V = Value;
using DSChangeStream = DocumentSourceChangeStream;
+using unittest::EnsureFCV;
+
static const Timestamp ts(100, 1);
static const repl::OpTime optime(ts, 1);
static const NamespaceString nss("unittests.change_stream");
-class EnsureFCV {
-public:
- using Version = ServerGlobalParams::FeatureCompatibility::Version;
- EnsureFCV(Version version)
- : _origVersion(serverGlobalParams.featureCompatibility.getVersion()) {
- serverGlobalParams.featureCompatibility.setVersion(version);
- }
- ~EnsureFCV() {
- serverGlobalParams.featureCompatibility.setVersion(_origVersion);
- }
-
-private:
- const Version _origVersion;
-};
-
class ChangeStreamStageTestNoSetup : public AggregationContextFixture {
public:
ChangeStreamStageTestNoSetup() : ChangeStreamStageTestNoSetup(nss) {}
diff --git a/src/mongo/db/pipeline/pipeline_test.cpp b/src/mongo/db/pipeline/pipeline_test.cpp
index aa58c26bdfa..4418e9dc9a4 100644
--- a/src/mongo/db/pipeline/pipeline_test.cpp
+++ b/src/mongo/db/pipeline/pipeline_test.cpp
@@ -54,8 +54,10 @@
#include "mongo/db/repl/replication_coordinator_mock.h"
#include "mongo/dbtests/dbtests.h"
#include "mongo/unittest/death_test.h"
+#include "mongo/unittest/ensure_fcv.h"
-namespace PipelineTests {
+namespace mongo {
+namespace {
using boost::intrusive_ptr;
using std::string;
@@ -63,32 +65,13 @@ using std::vector;
const NamespaceString kTestNss = NamespaceString("a.collection");
-namespace {
void setMockReplicationCoordinatorOnOpCtx(OperationContext* opCtx) {
repl::ReplicationCoordinator::set(
opCtx->getServiceContext(),
stdx::make_unique<repl::ReplicationCoordinatorMock>(opCtx->getServiceContext()));
}
-class EnsureFCV {
-public:
- using Version = ServerGlobalParams::FeatureCompatibility::Version;
- EnsureFCV(Version version)
- : _origVersion(serverGlobalParams.featureCompatibility.getVersion()) {
- serverGlobalParams.featureCompatibility.setVersion(version);
- }
- ~EnsureFCV() {
- serverGlobalParams.featureCompatibility.setVersion(_origVersion);
- }
-
-private:
- const Version _origVersion;
-};
-} // namespace
-
namespace Optimizations {
-using namespace mongo;
-
namespace Local {
BSONObj pipelineFromJsonArray(const std::string& jsonArray) {
@@ -1395,9 +1378,11 @@ TEST(PipelineOptimizationTest, ChangeStreamLookupDoesNotSwapWithMatchOnPostImage
// Make sure the $match stage stays at the end.
ASSERT(dynamic_cast<DocumentSourceMatch*>(pipeline->getSources().back().get()));
}
+
} // namespace Local
namespace Sharded {
+
class Base {
public:
// These all return json arrays of pipeline operators
@@ -1703,6 +1688,7 @@ class ShouldNotCoalesceUnwindNotOnAs : public Base {
} // namespace coalesceLookUpAndUnwind
namespace needsPrimaryShardMerger {
+
class needsPrimaryShardMergerBase : public Base {
public:
void run() override {
@@ -1911,8 +1897,6 @@ TEST_F(PipelineMustRunOnMongoSTest, SplittablePipelineRunsUnsplitOnMongoSIfSplit
} // namespace Sharded
} // namespace Optimizations
-namespace {
-
TEST(PipelineInitialSource, GeoNearInitialQuery) {
OperationContextNoop _opCtx;
const std::vector<BSONObj> rawPipeline = {
@@ -2229,7 +2213,6 @@ TEST_F(PipelineDependenciesTest, ShouldNotRequireTextScoreIfAvailableButDefinite
}
} // namespace Dependencies
-} // namespace
class All : public Suite {
public:
@@ -2262,4 +2245,5 @@ public:
SuiteInstance<All> myall;
-} // namespace PipelineTests
+} // namespace
+} // namespace mongo
diff --git a/src/mongo/db/repl/oplog_fetcher_test.cpp b/src/mongo/db/repl/oplog_fetcher_test.cpp
index b2195e50710..4b63bdc475f 100644
--- a/src/mongo/db/repl/oplog_fetcher_test.cpp
+++ b/src/mongo/db/repl/oplog_fetcher_test.cpp
@@ -37,6 +37,7 @@
#include "mongo/rpc/metadata/oplog_query_metadata.h"
#include "mongo/rpc/metadata/repl_set_metadata.h"
#include "mongo/stdx/memory.h"
+#include "mongo/unittest/ensure_fcv.h"
#include "mongo/unittest/task_executor_proxy.h"
#include "mongo/unittest/unittest.h"
#include "mongo/util/scopeguard.h"
@@ -265,22 +266,6 @@ TEST_F(OplogFetcherTest, AwaitDataTimeoutShouldBeAConstantUnderProtocolVersion0)
ASSERT_EQUALS(OplogFetcher::kDefaultProtocolZeroAwaitDataTimeout, timeout);
}
-class EnsureFCV {
-public:
- using Version = ServerGlobalParams::FeatureCompatibility::Version;
- EnsureFCV(Version version)
- : _version(version), _origVersion(serverGlobalParams.featureCompatibility.getVersion()) {
- serverGlobalParams.featureCompatibility.setVersion(_version);
- }
- ~EnsureFCV() {
- serverGlobalParams.featureCompatibility.setVersion(_origVersion);
- }
-
-private:
- const Version _version;
- const Version _origVersion;
-};
-
TEST_F(OplogFetcherTest, FindQueryHasNoReadconcernIfTermNotLastFetched) {
auto uninitializedTerm = OpTime::kUninitializedTerm;
ASSERT_NOT_EQUALS(dataReplicatorExternalState->currentTerm, uninitializedTerm);
diff --git a/src/mongo/unittest/ensure_fcv.h b/src/mongo/unittest/ensure_fcv.h
new file mode 100644
index 00000000000..63ba860ca45
--- /dev/null
+++ b/src/mongo/unittest/ensure_fcv.h
@@ -0,0 +1,56 @@
+/**
+ * Copyright (C) 2017 MongoDB Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * As a special exception, the copyright holders give permission to link the
+ * code of portions of this program with the OpenSSL library under certain
+ * conditions as described in each individual source file and distribute
+ * linked combinations including the program with the OpenSSL library. You
+ * must comply with the GNU Affero General Public License in all respects for
+ * all of the code used other than as permitted herein. If you modify file(s)
+ * with this exception, you may extend this exception to your version of the
+ * file(s), but you are not obligated to do so. If you do not wish to do so,
+ * delete this exception statement from your version. If you delete this
+ * exception statement from all source files in the program, then also delete
+ * it in the license file.
+ */
+
+#pragma once
+
+#include "mongo/db/server_options.h"
+
+namespace mongo {
+namespace unittest {
+
+/**
+ * Helper class for tests to set FCV to their desired version. Will unset
+ * FCV when its destructor runs.
+ */
+class EnsureFCV {
+public:
+ using Version = ServerGlobalParams::FeatureCompatibility::Version;
+ EnsureFCV(Version version)
+ : _origVersion(serverGlobalParams.featureCompatibility.getVersion()) {
+ serverGlobalParams.featureCompatibility.setVersion(version);
+ }
+ ~EnsureFCV() {
+ serverGlobalParams.featureCompatibility.setVersion(_origVersion);
+ }
+
+private:
+ const Version _origVersion;
+};
+
+} // namespace unittest
+} // namespace mongo