3131//
3232
3333#include " mongo/db/exec/queued_data_stage.h"
34+
3435#include " mongo/db/exec/working_set.h"
36+ #include " mongo/db/operation_context_noop.h"
37+ #include " mongo/db/service_context.h"
38+ #include " mongo/db/service_context_noop.h"
3539#include " mongo/stdx/memory.h"
3640#include " mongo/unittest/unittest.h"
41+ #include " mongo/util/clock_source_mock.h"
3742
3843using namespace mongo ;
3944
@@ -42,12 +47,38 @@ namespace {
4247using std::unique_ptr;
4348using stdx::make_unique;
4449
50+ class QueuedDataStageTest : public unittest ::Test {
51+ public:
52+ QueuedDataStageTest () {
53+ _service = stdx::make_unique<ServiceContextNoop>();
54+ _service.get ()->setFastClockSource (stdx::make_unique<ClockSourceMock>());
55+ _client = _service.get ()->makeClient (" test" );
56+ _opCtxNoop.reset (new OperationContextNoop (_client.get (), 0 ));
57+ _opCtx = _opCtxNoop.get ();
58+ }
59+
60+ protected:
61+ OperationContext* getOpCtx () {
62+ return _opCtx;
63+ }
64+
65+ private:
66+ OperationContext* _opCtx;
67+
68+ // Members of a class are destroyed in reverse order of declaration.
69+ // The UniqueClient must be destroyed before the ServiceContextNoop is destroyed.
70+ // The OperationContextNoop must be destroyed before the UniqueClient is destroyed.
71+ std::unique_ptr<ServiceContextNoop> _service;
72+ ServiceContext::UniqueClient _client;
73+ std::unique_ptr<OperationContextNoop> _opCtxNoop;
74+ };
75+
4576//
4677// Basic test that we get out valid stats objects.
4778//
48- TEST (QueuedDataStageTest, getValidStats) {
79+ TEST_F (QueuedDataStageTest, getValidStats) {
4980 WorkingSet ws;
50- auto mock = make_unique<QueuedDataStage>(nullptr , &ws);
81+ auto mock = make_unique<QueuedDataStage>(getOpCtx () , &ws);
5182 const CommonStats* commonStats = mock->getCommonStats ();
5283 ASSERT_EQUALS (commonStats->works , static_cast <size_t >(0 ));
5384 const SpecificStats* specificStats = mock->getSpecificStats ();
@@ -59,10 +90,10 @@ TEST(QueuedDataStageTest, getValidStats) {
5990//
6091// Test that our stats are updated as we perform operations.
6192//
62- TEST (QueuedDataStageTest, validateStats) {
93+ TEST_F (QueuedDataStageTest, validateStats) {
6394 WorkingSet ws;
6495 WorkingSetID wsID;
65- auto mock = make_unique<QueuedDataStage>(nullptr , &ws);
96+ auto mock = make_unique<QueuedDataStage>(getOpCtx () , &ws);
6697
6798 // make sure that we're at all zero
6899 const CommonStats* stats = mock->getCommonStats ();
0 commit comments