diff options
Diffstat (limited to 'src/mongo/db/op_observer_impl_test.cpp')
-rw-r--r-- | src/mongo/db/op_observer_impl_test.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/mongo/db/op_observer_impl_test.cpp b/src/mongo/db/op_observer_impl_test.cpp index 8e4b093fafa..16c59b16ef3 100644 --- a/src/mongo/db/op_observer_impl_test.cpp +++ b/src/mongo/db/op_observer_impl_test.cpp @@ -41,6 +41,7 @@ #include "mongo/db/read_write_concern_defaults.h" #include "mongo/db/read_write_concern_defaults_cache_lookup_mock.h" #include "mongo/db/repl/oplog.h" +#include "mongo/db/repl/oplog_entry.h" #include "mongo/db/repl/oplog_interface_local.h" #include "mongo/db/repl/repl_client_info.h" #include "mongo/db/repl/replication_coordinator_mock.h" @@ -445,6 +446,20 @@ TEST_F(OpObserverTest, OnRenameCollectionOmitsDropTargetFieldIfDropTargetUuidIsN ASSERT_BSONOBJ_EQ(oExpected, o); } +TEST_F(OpObserverTest, MustBePrimaryToWriteOplogEntries) { + OpObserverImpl opObserver; + auto opCtx = cc().makeOperationContext(); + + ASSERT_OK(repl::ReplicationCoordinator::get(opCtx.get()) + ->setFollowerMode(repl::MemberState::RS_SECONDARY)); + + Lock::GlobalWrite globalWrite(opCtx.get()); + WriteUnitOfWork wunit(opCtx.get()); + + // No-op writes should be prohibited. + ASSERT_THROWS_CODE(opObserver.onOpMessage(opCtx.get(), {}), DBException, ErrorCodes::NotMaster); +} + /** * Test fixture for testing OpObserver behavior specific to the SessionCatalog. */ |