diff options
Diffstat (limited to 'jstests/noPassthrough/oplog_writes_only_permitted_on_standalone.js')
-rw-r--r-- | jstests/noPassthrough/oplog_writes_only_permitted_on_standalone.js | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/jstests/noPassthrough/oplog_writes_only_permitted_on_standalone.js b/jstests/noPassthrough/oplog_writes_only_permitted_on_standalone.js new file mode 100644 index 00000000000..bb2af0f0ee7 --- /dev/null +++ b/jstests/noPassthrough/oplog_writes_only_permitted_on_standalone.js @@ -0,0 +1,43 @@ +/** + * Tests that oplog writes are forbidden on replica set members. In standalone mode, it is permitted + * to insert oplog entries. + * @tags: [ + * requires_persistence, + * requires_replication, + * ] + */ +(function() { + "use strict"; + + const rst = new ReplSetTest({nodes: 1}); + rst.startSet(); + rst.initiate(); + + let conn = rst.getPrimary(); + assert.writeOK(conn.getDB("test").coll.insert({_id: 0, a: 0})); + + let oplog = conn.getDB("local").oplog.rs; + + // Construct a valid oplog entry. + const lastOplogEntry = oplog.find().sort({ts: -1}).limit(1).toArray()[0]; + const highestTS = lastOplogEntry.ts; + const toInsert = Object.extend(lastOplogEntry, { + op: "u", + ns: "test.coll", + o: {$set: {a: 1}}, + o2: {_id: 0}, + ts: Timestamp(highestTS.getTime(), highestTS.getInc() + 1) + }); + + jsTestLog("Test that oplog writes are banned when replication is enabled."); + assert.writeErrorWithCode(oplog.insert(toInsert), ErrorCodes.InvalidNamespace); + + jsTestLog("Restart the node in standalone mode."); + rst.stop(0, undefined /*signal*/, undefined /*opts*/, {forRestart: true}); + conn = rst.start(0, {noReplSet: true, noCleanData: true}); + + jsTestLog("Test that oplog writes are permitted in standalone mode."); + assert.writeOK(conn.getDB("local").oplog.rs.insert(toInsert)); + + rst.stopSet(); +}()); |