diff options
author | Billy Donahue <billy.donahue@mongodb.com> | 2019-10-02 00:03:00 +0000 |
---|---|---|
committer | evergreen <evergreen@mongodb.com> | 2019-10-02 00:03:00 +0000 |
commit | 6adefc73b4990253e4f277b49b119db1a05b7490 (patch) | |
tree | cbad4fe8afa2418bd2b7b4bd33303b0e6be66bc6 /src/mongo/dbtests | |
parent | dfb22aca7b1e62693fd5272d37239a40000c3d0e (diff) | |
download | mongo-6adefc73b4990253e4f277b49b119db1a05b7490.tar.gz |
SERVER-43367 unittest framework refactor/fixes
- Segregate old-style dbtests into their own Suite initialization
system: OldStyleSuiteSpecification. This is where the funky
deprecated features can live on without interfering with the
Suite API. It also gives us a searchable base class to identify
them in the future.
OldStyleSuite has `setupTests()` and an `add<T>()` that
Suite does not have. Suite API can shrink when it doesn't
have to support these dbtest adaptor features.
Suite only needs non-template `add(name, callback)`.
- Add OldStyleSuiteInitializer to some dbtests that were missing it!
These didn't use SuiteInstance to register themselves and were
incorrect. They would self register, resulting in _allSuites()
holding a std::shared_ptr to a static-duration Suite object!
- Change `getSuite()` to return `Suite&` instead of `Suite*`.
- No more "self-registering" in Suite constructor. Registration
must be done as a separate post-construction step. This removes
some unusual lifetime management code and is easier to document.
Suite::getSuite(name) is the only way to make a Suite, and it
does the make_shared and registration calls with a pseudo-private
ConstructorEnable idiom.
- Suite->run() returns std::unique_ptr<Result> instead of
raw `Result*`. It's virtual to support OldStyleSuite behavior.
- Suite._ran does nothing. Removed.
- Result.cur does nothing. Removed.
- Switch to pass-by-value and std::move for most ctor args.
- Add explicit on 1-arg ctors.
- Get rid of TestHolder. It's just a 2-field struct.
- use fmt instead of snprintf
- TEST and TEST_F macros: generate TEST_TYPE once.
- TEST and TEST_F macros: inline the _agent variable.
- Mark _doRun as `override`.
- Terminology: replace CASE_NAME with SUITE_NAME.
- rename DeathTestImpl -> DeathTestBase
- move getDeathTestPattern into the test as a static member function
- refactor out some repetition from the comparator decl macros
- use if-constexpr and diamond relops to clean up the
ComparisonAssertion class.
- dbtests: conditionally skip some add<T> calls
- further dedup (DEATH_)TEST(_F) macros
Diffstat (limited to 'src/mongo/dbtests')
36 files changed, 197 insertions, 158 deletions
diff --git a/src/mongo/dbtests/basictests.cpp b/src/mongo/dbtests/basictests.cpp index c3160ef54bd..e116887abb3 100644 --- a/src/mongo/dbtests/basictests.cpp +++ b/src/mongo/dbtests/basictests.cpp @@ -356,9 +356,9 @@ public: } }; -class All : public Suite { +class All : public OldStyleSuiteSpecification { public: - All() : Suite("basic") {} + All() : OldStyleSuiteSpecification("basic") {} void setupTests() { add<RarelyTest>(); @@ -382,6 +382,6 @@ public: } }; -SuiteInstance<All> myall; +OldStyleSuiteInitializer<All> myall; } // namespace BasicTests diff --git a/src/mongo/dbtests/clienttests.cpp b/src/mongo/dbtests/clienttests.cpp index bdb97bed3df..77d690847cd 100644 --- a/src/mongo/dbtests/clienttests.cpp +++ b/src/mongo/dbtests/clienttests.cpp @@ -382,9 +382,9 @@ public: } }; -class All : public Suite { +class All : public OldStyleSuiteSpecification { public: - All() : Suite("client") {} + All() : OldStyleSuiteSpecification("client") {} void setupTests() { add<DropIndex>(); @@ -406,5 +406,5 @@ public: } }; -SuiteInstance<All> all; +OldStyleSuiteInitializer<All> all; } // namespace ClientTests diff --git a/src/mongo/dbtests/commandtests.cpp b/src/mongo/dbtests/commandtests.cpp index d2479943ffc..2a464621bcd 100644 --- a/src/mongo/dbtests/commandtests.cpp +++ b/src/mongo/dbtests/commandtests.cpp @@ -361,9 +361,9 @@ public: } }; -class All : public Suite { +class All : public OldStyleSuiteSpecification { public: - All() : Suite("commands") {} + All() : OldStyleSuiteSpecification("commands") {} void setupTests() { add<FileMD5::Type0>(); @@ -380,5 +380,5 @@ public: } }; -SuiteInstance<All> all; +OldStyleSuiteInitializer<All> all; } // namespace CommandTests diff --git a/src/mongo/dbtests/counttests.cpp b/src/mongo/dbtests/counttests.cpp index a5a614016da..86f3ac51b71 100644 --- a/src/mongo/dbtests/counttests.cpp +++ b/src/mongo/dbtests/counttests.cpp @@ -157,9 +157,9 @@ public: } }; -class All : public Suite { +class All : public OldStyleSuiteSpecification { public: - All() : Suite("count") {} + All() : OldStyleSuiteSpecification("count") {} void setupTests() { add<Basic>(); @@ -169,6 +169,6 @@ public: } }; -SuiteInstance<All> myall; +OldStyleSuiteInitializer<All> myall; } // namespace CountTests diff --git a/src/mongo/dbtests/dbhelper_tests.cpp b/src/mongo/dbtests/dbhelper_tests.cpp index 427faa513de..f2b567c4a7b 100644 --- a/src/mongo/dbtests/dbhelper_tests.cpp +++ b/src/mongo/dbtests/dbhelper_tests.cpp @@ -88,13 +88,15 @@ private: int _max; }; -class All : public Suite { +class All : public OldStyleSuiteSpecification { public: - All() : Suite("remove") {} + All() : OldStyleSuiteSpecification("remove") {} void setupTests() { add<RemoveRange>(); } -} myall; +}; + +OldStyleSuiteInitializer<All> myall; } // namespace } // namespace mongo diff --git a/src/mongo/dbtests/deferred_writer.cpp b/src/mongo/dbtests/deferred_writer.cpp index da51278c392..ec99966c84e 100644 --- a/src/mongo/dbtests/deferred_writer.cpp +++ b/src/mongo/dbtests/deferred_writer.cpp @@ -370,9 +370,9 @@ private: static const int kDocsPerWorker = 100; }; -class DeferredWriterTests : public Suite { +class DeferredWriterTests : public OldStyleSuiteSpecification { public: - DeferredWriterTests() : Suite("deferred_writer_tests") {} + DeferredWriterTests() : OldStyleSuiteSpecification("deferred_writer_tests") {} void setupTests() { add<DeferredWriterTestEmpty>(); @@ -382,5 +382,8 @@ public: add<DeferredWriterTestCap>(); add<DeferredWriterTestAsync>(); } -} deferredWriterTests; +}; + +OldStyleSuiteInitializer<DeferredWriterTests> deferredWriterTests; + } // namespace deferred_writer_tests diff --git a/src/mongo/dbtests/directclienttests.cpp b/src/mongo/dbtests/directclienttests.cpp index 6ca684003d9..c1b80628851 100644 --- a/src/mongo/dbtests/directclienttests.cpp +++ b/src/mongo/dbtests/directclienttests.cpp @@ -190,9 +190,9 @@ public: } }; -class All : public Suite { +class All : public OldStyleSuiteSpecification { public: - All() : Suite("directclient") {} + All() : OldStyleSuiteSpecification("directclient") {} void setupTests() { add<Capped>(); add<InsertMany>(); @@ -205,5 +205,5 @@ public: } }; -SuiteInstance<All> myall; +OldStyleSuiteInitializer<All> myall; } // namespace DirectClientTests diff --git a/src/mongo/dbtests/gle_test.cpp b/src/mongo/dbtests/gle_test.cpp index 279de9fff24..6bc20c08182 100644 --- a/src/mongo/dbtests/gle_test.cpp +++ b/src/mongo/dbtests/gle_test.cpp @@ -115,9 +115,9 @@ public: } }; -class All : public Suite { +class All : public OldStyleSuiteSpecification { public: - All() : Suite("gle") {} + All() : OldStyleSuiteSpecification("gle") {} void setupTests() { add<GetLastErrorClean>(); @@ -126,5 +126,5 @@ public: } }; -SuiteInstance<All> myall; +OldStyleSuiteInitializer<All> myall; } // namespace diff --git a/src/mongo/dbtests/indexcatalogtests.cpp b/src/mongo/dbtests/indexcatalogtests.cpp index f51a4e2852a..949b6bdd742 100644 --- a/src/mongo/dbtests/indexcatalogtests.cpp +++ b/src/mongo/dbtests/indexcatalogtests.cpp @@ -231,9 +231,9 @@ private: Database* _db; }; -class IndexCatalogTests : public Suite { +class IndexCatalogTests : public OldStyleSuiteSpecification { public: - IndexCatalogTests() : Suite("indexcatalogtests") {} + IndexCatalogTests() : OldStyleSuiteSpecification("indexcatalogtests") {} void setupTests() { add<IndexIteratorTests>(); add<IndexCatalogEntryDroppedTest>(); @@ -241,5 +241,5 @@ public: } }; -SuiteInstance<IndexCatalogTests> indexCatalogTests; +OldStyleSuiteInitializer<IndexCatalogTests> indexCatalogTests; } // namespace IndexCatalogTests diff --git a/src/mongo/dbtests/indexupdatetests.cpp b/src/mongo/dbtests/indexupdatetests.cpp index 362b34ae44a..6ceebc55c1b 100644 --- a/src/mongo/dbtests/indexupdatetests.cpp +++ b/src/mongo/dbtests/indexupdatetests.cpp @@ -625,21 +625,32 @@ public: } }; -class IndexUpdateTests : public Suite { +class IndexUpdateTests : public OldStyleSuiteSpecification { public: - IndexUpdateTests() : Suite("indexupdate") {} + IndexUpdateTests() : OldStyleSuiteSpecification("indexupdate") {} + + // Must be evaluated at test run() time, not static-init time. + static bool shouldSkip() { + return mongo::storageGlobalParams.engine == "mobile"; + } + + template <typename T> + void addIf() { + addNameCallback(nameForTestClass<T>(), [] { + if (!shouldSkip()) + T().run(); + }); + } void setupTests() { + // These tests check that index creation ignores the unique constraint when told to. + // The mobile storage engine does not support duplicate keys in unique indexes so these + // tests are disabled. + addIf<InsertBuildIgnoreUnique<true>>(); + addIf<InsertBuildIgnoreUnique<false>>(); + addIf<InsertBuildEnforceUnique<true>>(); + addIf<InsertBuildEnforceUnique<false>>(); - if (mongo::storageGlobalParams.engine != "mobile") { - // These tests check that index creation ignores the unique constraint when told to. - // The mobile storage engine does not support duplicate keys in unique indexes so these - // tests are disabled. - add<InsertBuildIgnoreUnique<true>>(); - add<InsertBuildIgnoreUnique<false>>(); - add<InsertBuildEnforceUnique<true>>(); - add<InsertBuildEnforceUnique<false>>(); - } add<InsertBuildIndexInterrupt>(); add<InsertBuildIdIndexInterrupt>(); add<SameSpecDifferentOption>(); @@ -661,6 +672,8 @@ public: add<BuildingIndexWithCollationWhenSymbolDataExistsShouldFail>(); add<IndexingSymbolWithInheritedCollationShouldFail>(); } -} indexUpdateTests; +}; + +OldStyleSuiteInitializer<IndexUpdateTests> indexUpdateTests; } // namespace IndexUpdateTests diff --git a/src/mongo/dbtests/jsobjtests.cpp b/src/mongo/dbtests/jsobjtests.cpp index 56a58e6e852..08ae278aa12 100644 --- a/src/mongo/dbtests/jsobjtests.cpp +++ b/src/mongo/dbtests/jsobjtests.cpp @@ -1985,9 +1985,9 @@ public: } }; -class All : public Suite { +class All : public OldStyleSuiteSpecification { public: - All() : Suite("jsobj") {} + All() : OldStyleSuiteSpecification("jsobj") {} void setupTests() { add<BufBuilderBasic>(); @@ -2081,6 +2081,6 @@ public: } }; -SuiteInstance<All> myall; +OldStyleSuiteInitializer<All> myall; } // namespace JsobjTests diff --git a/src/mongo/dbtests/jstests.cpp b/src/mongo/dbtests/jstests.cpp index 44ccf7b6b5a..7ab5d285e28 100644 --- a/src/mongo/dbtests/jstests.cpp +++ b/src/mongo/dbtests/jstests.cpp @@ -1547,9 +1547,9 @@ public: } }; -class All : public Suite { +class All : public OldStyleSuiteSpecification { public: - All() : Suite("js") {} + All() : OldStyleSuiteSpecification("js") {} template <ScopeFactory scopeFactory> void setupTestsWithScopeFactory() { @@ -1609,6 +1609,6 @@ public: } }; -SuiteInstance<All> myall; +OldStyleSuiteInitializer<All> myall; } // namespace JSTests diff --git a/src/mongo/dbtests/logical_sessions_tests.cpp b/src/mongo/dbtests/logical_sessions_tests.cpp index a9da89f05bb..13d3cb75e14 100644 --- a/src/mongo/dbtests/logical_sessions_tests.cpp +++ b/src/mongo/dbtests/logical_sessions_tests.cpp @@ -269,9 +269,9 @@ public: } }; -class All : public Suite { +class All : public OldStyleSuiteSpecification { public: - All() : Suite("logical_sessions") {} + All() : OldStyleSuiteSpecification("logical_sessions") {} void setupTests() { add<SessionsCollectionStandaloneRemoveTest>(); @@ -280,7 +280,7 @@ public: } }; -SuiteInstance<All> all; +OldStyleSuiteInitializer<All> all; } // namespace } // namespace mongo diff --git a/src/mongo/dbtests/matchertests.cpp b/src/mongo/dbtests/matchertests.cpp index 3c9107c3181..b0fb98ded31 100644 --- a/src/mongo/dbtests/matchertests.cpp +++ b/src/mongo/dbtests/matchertests.cpp @@ -300,9 +300,9 @@ public: } }; -class All : public Suite { +class All : public OldStyleSuiteSpecification { public: - All() : Suite("matcher") {} + All() : OldStyleSuiteSpecification("matcher") {} #define ADD_BOTH(TEST) add<TEST<Matcher>>(); @@ -325,6 +325,6 @@ public: } }; -SuiteInstance<All> dball; +OldStyleSuiteInitializer<All> dball; } // namespace MatcherTests diff --git a/src/mongo/dbtests/pdfiletests.cpp b/src/mongo/dbtests/pdfiletests.cpp index a57a3fb0619..0ed15a37d23 100644 --- a/src/mongo/dbtests/pdfiletests.cpp +++ b/src/mongo/dbtests/pdfiletests.cpp @@ -158,9 +158,9 @@ public: }; } // namespace Insert -class All : public Suite { +class All : public OldStyleSuiteSpecification { public: - All() : Suite("pdfile") {} + All() : OldStyleSuiteSpecification("pdfile") {} void setupTests() { add<Insert::InsertNoId>(); @@ -170,6 +170,6 @@ public: } }; -SuiteInstance<All> myall; +OldStyleSuiteInitializer<All> myall; } // namespace PdfileTests diff --git a/src/mongo/dbtests/plan_ranking.cpp b/src/mongo/dbtests/plan_ranking.cpp index b4c9d67380e..18f4795f13c 100644 --- a/src/mongo/dbtests/plan_ranking.cpp +++ b/src/mongo/dbtests/plan_ranking.cpp @@ -691,9 +691,9 @@ public: } }; -class All : public Suite { +class All : public OldStyleSuiteSpecification { public: - All() : Suite("query_plan_ranking") {} + All() : OldStyleSuiteSpecification("query_plan_ranking") {} void setupTests() { add<PlanRankingIntersectOverride>(); @@ -712,6 +712,6 @@ public: } }; -SuiteInstance<All> planRankingAll; +OldStyleSuiteInitializer<All> planRankingAll; } // namespace PlanRankingTests diff --git a/src/mongo/dbtests/query_stage_and.cpp b/src/mongo/dbtests/query_stage_and.cpp index a4059b60115..f06e8fb3589 100644 --- a/src/mongo/dbtests/query_stage_and.cpp +++ b/src/mongo/dbtests/query_stage_and.cpp @@ -1339,9 +1339,9 @@ public: }; -class All : public Suite { +class All : public OldStyleSuiteSpecification { public: - All() : Suite("query_stage_and") {} + All() : OldStyleSuiteSpecification("query_stage_and") {} void setupTests() { add<QueryStageAndHashDeleteDuringYield>(); @@ -1366,6 +1366,6 @@ public: } }; -SuiteInstance<All> queryStageAndAll; +OldStyleSuiteInitializer<All> queryStageAndAll; } // namespace QueryStageAnd diff --git a/src/mongo/dbtests/query_stage_count.cpp b/src/mongo/dbtests/query_stage_count.cpp index 6444ee4b9ea..e8bdc4a0dba 100644 --- a/src/mongo/dbtests/query_stage_count.cpp +++ b/src/mongo/dbtests/query_stage_count.cpp @@ -359,9 +359,9 @@ public: } }; -class All : public Suite { +class All : public OldStyleSuiteSpecification { public: - All() : Suite("query_stage_count") {} + All() : OldStyleSuiteSpecification("query_stage_count") {} void setupTests() { add<QueryStageCountNoChangeDuringYield>(); @@ -372,6 +372,8 @@ public: add<QueryStageCountUpdateDuringYield>(); add<QueryStageCountMultiKeyDuringYield>(); } -} QueryStageCountAll; +}; + +OldStyleSuiteInitializer<All> queryStageCountAll; } // namespace QueryStageCount diff --git a/src/mongo/dbtests/query_stage_count_scan.cpp b/src/mongo/dbtests/query_stage_count_scan.cpp index 0b3e05c5cba..bba51c5fe00 100644 --- a/src/mongo/dbtests/query_stage_count_scan.cpp +++ b/src/mongo/dbtests/query_stage_count_scan.cpp @@ -578,9 +578,9 @@ public: } }; -class All : public Suite { +class All : public OldStyleSuiteSpecification { public: - All() : Suite("query_stage_count_scan") {} + All() : OldStyleSuiteSpecification("query_stage_count_scan") {} void setupTests() { add<QueryStageCountScanDups>(); @@ -596,6 +596,6 @@ public: } }; -SuiteInstance<All> queryStageCountScanAll; +OldStyleSuiteInitializer<All> queryStageCountScanAll; } // namespace QueryStageCountScan diff --git a/src/mongo/dbtests/query_stage_delete.cpp b/src/mongo/dbtests/query_stage_delete.cpp index 6b9659fc1c5..db316f5a15f 100644 --- a/src/mongo/dbtests/query_stage_delete.cpp +++ b/src/mongo/dbtests/query_stage_delete.cpp @@ -249,9 +249,9 @@ public: } }; -class All : public Suite { +class All : public OldStyleSuiteSpecification { public: - All() : Suite("query_stage_delete") {} + All() : OldStyleSuiteSpecification("query_stage_delete") {} void setupTests() { // Stage-specific tests below. @@ -260,6 +260,6 @@ public: } }; -SuiteInstance<All> all; +OldStyleSuiteInitializer<All> all; } // namespace QueryStageDelete diff --git a/src/mongo/dbtests/query_stage_distinct.cpp b/src/mongo/dbtests/query_stage_distinct.cpp index c82e4c5fe00..fdfa2c06469 100644 --- a/src/mongo/dbtests/query_stage_distinct.cpp +++ b/src/mongo/dbtests/query_stage_distinct.cpp @@ -304,9 +304,9 @@ public: // XXX: add a test case with bounds where skipping to the next key gets us a result that's not // valid w.r.t. our query. -class All : public Suite { +class All : public OldStyleSuiteSpecification { public: - All() : Suite("query_stage_distinct") {} + All() : OldStyleSuiteSpecification("query_stage_distinct") {} void setupTests() { add<QueryStageDistinctBasic>(); @@ -315,6 +315,6 @@ public: } }; -SuiteInstance<All> queryStageDistinctAll; +OldStyleSuiteInitializer<All> queryStageDistinctAll; } // namespace QueryStageDistinct diff --git a/src/mongo/dbtests/query_stage_fetch.cpp b/src/mongo/dbtests/query_stage_fetch.cpp index 61a472f82e2..fbc35ccbc47 100644 --- a/src/mongo/dbtests/query_stage_fetch.cpp +++ b/src/mongo/dbtests/query_stage_fetch.cpp @@ -224,9 +224,9 @@ public: } }; -class All : public Suite { +class All : public OldStyleSuiteSpecification { public: - All() : Suite("query_stage_fetch") {} + All() : OldStyleSuiteSpecification("query_stage_fetch") {} void setupTests() { add<FetchStageAlreadyFetched>(); @@ -234,6 +234,6 @@ public: } }; -SuiteInstance<All> queryStageFetchAll; +OldStyleSuiteInitializer<All> queryStageFetchAll; } // namespace QueryStageFetch diff --git a/src/mongo/dbtests/query_stage_ixscan.cpp b/src/mongo/dbtests/query_stage_ixscan.cpp index ca36a6710d7..e9ac3c744d8 100644 --- a/src/mongo/dbtests/query_stage_ixscan.cpp +++ b/src/mongo/dbtests/query_stage_ixscan.cpp @@ -314,9 +314,9 @@ public: } }; -class All : public Suite { +class All : public OldStyleSuiteSpecification { public: - All() : Suite("query_stage_ixscan") {} + All() : OldStyleSuiteSpecification("query_stage_ixscan") {} void setupTests() { add<QueryStageIxscanInitializeStats>(); @@ -325,6 +325,8 @@ public: add<QueryStageIxscanInsertDuringSaveExclusive2>(); add<QueryStageIxscanInsertDuringSaveReverse>(); } -} QueryStageIxscanAll; +}; + +OldStyleSuiteInitializer<All> aueryStageIxscanAll; } // namespace QueryStageIxscan diff --git a/src/mongo/dbtests/query_stage_limit_skip.cpp b/src/mongo/dbtests/query_stage_limit_skip.cpp index 69dd1d5b6da..7d5fba46ae1 100644 --- a/src/mongo/dbtests/query_stage_limit_skip.cpp +++ b/src/mongo/dbtests/query_stage_limit_skip.cpp @@ -112,15 +112,15 @@ protected: OperationContext* const _opCtx = _uniqOpCtx.get(); }; -class All : public Suite { +class All : public OldStyleSuiteSpecification { public: - All() : Suite("query_stage_limit_skip") {} + All() : OldStyleSuiteSpecification("query_stage_limit_skip") {} void setupTests() { add<QueryStageLimitSkipBasicTest>(); } }; -SuiteInstance<All> queryStageLimitSkipAll; +OldStyleSuiteInitializer<All> queryStageLimitSkipAll; } // namespace diff --git a/src/mongo/dbtests/query_stage_merge_sort.cpp b/src/mongo/dbtests/query_stage_merge_sort.cpp index 75795c5978e..3e296b1e07b 100644 --- a/src/mongo/dbtests/query_stage_merge_sort.cpp +++ b/src/mongo/dbtests/query_stage_merge_sort.cpp @@ -871,9 +871,9 @@ public: } }; -class All : public Suite { +class All : public OldStyleSuiteSpecification { public: - All() : Suite("query_stage_merge_sort_test") {} + All() : OldStyleSuiteSpecification("query_stage_merge_sort_test") {} void setupTests() { add<QueryStageMergeSortPrefixIndex>(); @@ -889,6 +889,6 @@ public: } }; -SuiteInstance<All> queryStageMergeSortTest; +OldStyleSuiteInitializer<All> queryStageMergeSortTest; } // namespace QueryStageMergeSortTests diff --git a/src/mongo/dbtests/query_stage_sort.cpp b/src/mongo/dbtests/query_stage_sort.cpp index 6332810b5cc..5676ba90157 100644 --- a/src/mongo/dbtests/query_stage_sort.cpp +++ b/src/mongo/dbtests/query_stage_sort.cpp @@ -588,9 +588,9 @@ public: } }; -class All : public Suite { +class All : public OldStyleSuiteSpecification { public: - All() : Suite("query_stage_sort") {} + All() : OldStyleSuiteSpecification("query_stage_sort") {} void setupTests() { add<QueryStageSortInc>(); @@ -608,6 +608,6 @@ public: } }; -SuiteInstance<All> queryStageSortTest; +OldStyleSuiteInitializer<All> queryStageSortTest; } // namespace QueryStageSortTests diff --git a/src/mongo/dbtests/query_stage_tests.cpp b/src/mongo/dbtests/query_stage_tests.cpp index f9178555ce2..f7c7dcf85ac 100644 --- a/src/mongo/dbtests/query_stage_tests.cpp +++ b/src/mongo/dbtests/query_stage_tests.cpp @@ -227,9 +227,9 @@ public: } }; -class All : public Suite { +class All : public OldStyleSuiteSpecification { public: - All() : Suite("query_stage_tests") {} + All() : OldStyleSuiteSpecification("query_stage_tests") {} void setupTests() { add<QueryStageIXScanBasic>(); @@ -240,6 +240,6 @@ public: } }; -SuiteInstance<All> queryStageTestsAll; +OldStyleSuiteInitializer<All> queryStageTestsAll; } // namespace QueryStageTests diff --git a/src/mongo/dbtests/query_stage_update.cpp b/src/mongo/dbtests/query_stage_update.cpp index 665ae70f031..c0dc47528e4 100644 --- a/src/mongo/dbtests/query_stage_update.cpp +++ b/src/mongo/dbtests/query_stage_update.cpp @@ -549,9 +549,9 @@ public: } }; -class All : public Suite { +class All : public OldStyleSuiteSpecification { public: - All() : Suite("query_stage_update") {} + All() : OldStyleSuiteSpecification("query_stage_update") {} void setupTests() { // Stage-specific tests below. @@ -562,6 +562,6 @@ public: } }; -SuiteInstance<All> all; +OldStyleSuiteInitializer<All> all; } // namespace QueryStageUpdate diff --git a/src/mongo/dbtests/querytests.cpp b/src/mongo/dbtests/querytests.cpp index 47cb3f55f4d..ba0a9eac64d 100644 --- a/src/mongo/dbtests/querytests.cpp +++ b/src/mongo/dbtests/querytests.cpp @@ -1865,9 +1865,9 @@ public: } }; -class All : public Suite { +class All : public OldStyleSuiteSpecification { public: - All() : Suite("query") {} + All() : OldStyleSuiteSpecification("query") {} void setupTests() { add<FindingStart>(); @@ -1926,7 +1926,7 @@ public: } }; -SuiteInstance<All> myall; +OldStyleSuiteInitializer<All> myall; } // namespace QueryTests } // namespace diff --git a/src/mongo/dbtests/repltests.cpp b/src/mongo/dbtests/repltests.cpp index 95e69a9e8cf..4c7bc1b51a5 100644 --- a/src/mongo/dbtests/repltests.cpp +++ b/src/mongo/dbtests/repltests.cpp @@ -1334,9 +1334,9 @@ public: } }; -class All : public Suite { +class All : public OldStyleSuiteSpecification { public: - All() : Suite("repl") {} + All() : OldStyleSuiteSpecification("repl") {} void setupTests() { add<LogBasic>(); @@ -1394,6 +1394,6 @@ public: } }; -SuiteInstance<All> myall; +OldStyleSuiteInitializer<All> myall; } // namespace ReplTests diff --git a/src/mongo/dbtests/rollbacktests.cpp b/src/mongo/dbtests/rollbacktests.cpp index d9417770b49..0276ef65381 100644 --- a/src/mongo/dbtests/rollbacktests.cpp +++ b/src/mongo/dbtests/rollbacktests.cpp @@ -715,9 +715,9 @@ public: }; -class All : public Suite { +class All : public OldStyleSuiteSpecification { public: - All() : Suite("rollback") {} + All() : OldStyleSuiteSpecification("rollback") {} template <template <bool> class T> void addAll() { @@ -759,6 +759,6 @@ public: } }; -SuiteInstance<All> all; +OldStyleSuiteInitializer<All> all; } // namespace RollbackTests diff --git a/src/mongo/dbtests/socktests.cpp b/src/mongo/dbtests/socktests.cpp index a59aa3b4702..1f06dc71097 100644 --- a/src/mongo/dbtests/socktests.cpp +++ b/src/mongo/dbtests/socktests.cpp @@ -52,14 +52,14 @@ public: } }; -class All : public Suite { +class All : public OldStyleSuiteSpecification { public: - All() : Suite("sock") {} + All() : OldStyleSuiteSpecification("sock") {} void setupTests() { add<HostByName>(); } }; -SuiteInstance<All> myall; +OldStyleSuiteInitializer<All> myall; } // namespace SockTests diff --git a/src/mongo/dbtests/storage_timestamp_tests.cpp b/src/mongo/dbtests/storage_timestamp_tests.cpp index 2dba77e964d..e8944a069a0 100644 --- a/src/mongo/dbtests/storage_timestamp_tests.cpp +++ b/src/mongo/dbtests/storage_timestamp_tests.cpp @@ -86,6 +86,7 @@ namespace mongo { namespace { + /** * RAII type for operating at a timestamp. Will remove any timestamping when the object destructs. */ @@ -3416,63 +3417,76 @@ public: } }; -class AllStorageTimestampTests : public unittest::Suite { +class AllStorageTimestampTests : public unittest::OldStyleSuiteSpecification { public: - AllStorageTimestampTests() : unittest::Suite("StorageTimestampTests") {} - void setupTests() { + AllStorageTimestampTests() : unittest::OldStyleSuiteSpecification("StorageTimestampTests") {} + + // Must be evaluated at test run() time, not static-init time. + static bool shouldSkip() { // Only run on storage engines that support snapshot reads. auto storageEngine = cc().getServiceContext()->getStorageEngine(); if (!storageEngine->supportsReadConcernSnapshot() || !mongo::serverGlobalParams.enableMajorityReadConcern) { unittest::log() << "Skipping this test suite because storage engine " << storageGlobalParams.engine << " does not support timestamp writes."; - return; + return true; } + return false; + } - add<SecondaryInsertTimes>(); - add<SecondaryArrayInsertTimes>(); - add<SecondaryDeleteTimes>(); - add<SecondaryUpdateTimes>(); - add<SecondaryInsertToUpsert>(); - add<SecondaryAtomicApplyOps>(); - add<SecondaryAtomicApplyOpsWCEToNonAtomic>(); - add<SecondaryCreateCollection>(); - add<SecondaryCreateTwoCollections>(); - add<SecondaryCreateCollectionBetweenInserts>(); - add<PrimaryCreateCollectionInApplyOps>(); - add<SecondarySetIndexMultikeyOnInsert>(); - add<InitialSyncSetIndexMultikeyOnInsert>(); - add<PrimarySetIndexMultikeyOnInsert>(); - add<PrimarySetIndexMultikeyOnInsertUnreplicated>(); - add<PrimarySetsMultikeyInsideMultiDocumentTransaction>(); - add<InitializeMinValid>(); - add<SetMinValidInitialSyncFlag>(); - add<SetMinValidToAtLeast>(); - add<SetMinValidAppliedThrough>(); + template <typename T> + void addIf() { + addNameCallback(nameForTestClass<T>(), [] { + if (!shouldSkip()) + T().run(); + }); + } + + void setupTests() { + addIf<SecondaryInsertTimes>(); + addIf<SecondaryArrayInsertTimes>(); + addIf<SecondaryDeleteTimes>(); + addIf<SecondaryUpdateTimes>(); + addIf<SecondaryInsertToUpsert>(); + addIf<SecondaryAtomicApplyOps>(); + addIf<SecondaryAtomicApplyOpsWCEToNonAtomic>(); + addIf<SecondaryCreateCollection>(); + addIf<SecondaryCreateTwoCollections>(); + addIf<SecondaryCreateCollectionBetweenInserts>(); + addIf<PrimaryCreateCollectionInApplyOps>(); + addIf<SecondarySetIndexMultikeyOnInsert>(); + addIf<InitialSyncSetIndexMultikeyOnInsert>(); + addIf<PrimarySetIndexMultikeyOnInsert>(); + addIf<PrimarySetIndexMultikeyOnInsertUnreplicated>(); + addIf<PrimarySetsMultikeyInsideMultiDocumentTransaction>(); + addIf<InitializeMinValid>(); + addIf<SetMinValidInitialSyncFlag>(); + addIf<SetMinValidToAtLeast>(); + addIf<SetMinValidAppliedThrough>(); // KVDropDatabase<SimulatePrimary> - add<KVDropDatabase<false>>(); - add<KVDropDatabase<true>>(); + addIf<KVDropDatabase<false>>(); + addIf<KVDropDatabase<true>>(); // TimestampIndexBuilds<SimulatePrimary> - add<TimestampIndexBuilds<false>>(); - add<TimestampIndexBuilds<true>>(); + addIf<TimestampIndexBuilds<false>>(); + addIf<TimestampIndexBuilds<true>>(); // TODO (SERVER-40894): Make index builds timestamp drained writes - // add<TimestampIndexBuildDrain<false>>(); - // add<TimestampIndexBuildDrain<true>>(); - add<TimestampMultiIndexBuilds>(); - add<TimestampMultiIndexBuildsDuringRename>(); - add<TimestampIndexDrops>(); - add<TimestampIndexBuilderOnPrimary>(); - add<SecondaryReadsDuringBatchApplicationAreAllowed>(); - add<ViewCreationSeparateTransaction>(); - add<CreateCollectionWithSystemIndex>(); - add<MultiDocumentTransaction>(); - add<MultiOplogEntryTransaction>(); - add<CommitPreparedMultiOplogEntryTransaction>(); - add<AbortPreparedMultiOplogEntryTransaction>(); - add<PreparedMultiDocumentTransaction>(); - add<AbortedPreparedMultiDocumentTransaction>(); + // addIf<TimestampIndexBuildDrain<false>>(); + // addIf<TimestampIndexBuildDrain<true>>(); + addIf<TimestampMultiIndexBuilds>(); + addIf<TimestampMultiIndexBuildsDuringRename>(); + addIf<TimestampIndexDrops>(); + addIf<TimestampIndexBuilderOnPrimary>(); + addIf<SecondaryReadsDuringBatchApplicationAreAllowed>(); + addIf<ViewCreationSeparateTransaction>(); + addIf<CreateCollectionWithSystemIndex>(); + addIf<MultiDocumentTransaction>(); + addIf<MultiOplogEntryTransaction>(); + addIf<CommitPreparedMultiOplogEntryTransaction>(); + addIf<AbortPreparedMultiOplogEntryTransaction>(); + addIf<PreparedMultiDocumentTransaction>(); + addIf<AbortedPreparedMultiDocumentTransaction>(); } }; -unittest::SuiteInstance<AllStorageTimestampTests> allStorageTimestampTests; +unittest::OldStyleSuiteInitializer<AllStorageTimestampTests> allStorageTimestampTests; } // namespace mongo diff --git a/src/mongo/dbtests/threadedtests.cpp b/src/mongo/dbtests/threadedtests.cpp index 95ff64d1e8b..7395c8d5066 100644 --- a/src/mongo/dbtests/threadedtests.cpp +++ b/src/mongo/dbtests/threadedtests.cpp @@ -289,9 +289,9 @@ private: } }; -class All : public Suite { +class All : public OldStyleSuiteSpecification { public: - All() : Suite("threading") {} + All() : OldStyleSuiteSpecification("threading") {} void setupTests() { // Slack is a test to see how long it takes for another thread to pick up @@ -307,5 +307,5 @@ public: } }; -SuiteInstance<All> myall; +OldStyleSuiteInitializer<All> myall; } // namespace ThreadedTests diff --git a/src/mongo/dbtests/updatetests.cpp b/src/mongo/dbtests/updatetests.cpp index 62bed088466..f37dc9adb9b 100644 --- a/src/mongo/dbtests/updatetests.cpp +++ b/src/mongo/dbtests/updatetests.cpp @@ -1998,9 +1998,9 @@ class setswitchint : public Base { } // namespace basic -class All : public Suite { +class All : public OldStyleSuiteSpecification { public: - All() : Suite("update") {} + All() : OldStyleSuiteSpecification("update") {} void setupTests() { add<ModId>(); add<ModNonmodMix>(); @@ -2118,6 +2118,6 @@ public: } }; -SuiteInstance<All> myall; +OldStyleSuiteInitializer<All> myall; } // namespace UpdateTests diff --git a/src/mongo/dbtests/validate_tests.cpp b/src/mongo/dbtests/validate_tests.cpp index 8d5762da76f..9a893435bb3 100644 --- a/src/mongo/dbtests/validate_tests.cpp +++ b/src/mongo/dbtests/validate_tests.cpp @@ -1404,9 +1404,9 @@ public: } }; -class ValidateTests : public Suite { +class ValidateTests : public OldStyleSuiteSpecification { public: - ValidateTests() : Suite("validate_tests") {} + ValidateTests() : OldStyleSuiteSpecification("validate_tests") {} void setupTests() { // Add tests for both full validate and non-full validate. @@ -1445,5 +1445,8 @@ public: add<ValidateMissingIndexEntryResults<false, false>>(); add<ValidateExtraIndexEntryResults<false, false>>(); } -} validateTests; +}; + +OldStyleSuiteInitializer<ValidateTests> validateTests; + } // namespace ValidateTests |