trying to write the according tests :)

This commit is contained in:
Patrick Schubert
2024-02-19 15:03:00 +01:00
parent 8e1e9e66c4
commit 0b1d32753f
3 changed files with 39 additions and 4 deletions

View File

@@ -231,6 +231,11 @@ MongoConnection.prototype.close = function() {
Future.wrap(_.bind(self.client.close, self.client))(true).wait();
};
MongoConnection.prototype._setOplogHandle = function(oplogHandle) {
this._oplogHandle = oplogHandle;
return this;
};
// Returns the Mongo Collection object; may yield.
MongoConnection.prototype.rawCollection = function (collectionName) {
var self = this;

View File

@@ -30,6 +30,7 @@ OplogHandle = function (oplogUrl, dbName) {
var self = this;
self._oplogUrl = oplogUrl;
self._dbName = dbName;
console.log('OplogHandle CONSTRUCTOR()');
self._oplogLastEntryConnection = null;
self._oplogTailConnection = null;
@@ -85,6 +86,8 @@ OplogHandle = function (oplogUrl, dbName) {
self._startTailing();
};
MongoInternals.OplogHandle = OplogHandle;
Object.assign(OplogHandle.prototype, {
stop: function () {
var self = this;
@@ -241,7 +244,7 @@ Object.assign(OplogHandle.prototype, {
self._lastProcessedTS = lastOplogEntry.ts;
}
// These 2 settings allow you to either only watch certain collections (oplogWatchCollections), or exclude some collections you don't want to watch for oplog updates (oplogExcludeCollections)
// These 2 settings allow you to either only watch certain collections (oplogIncludeCollections), or exclude some collections you don't want to watch for oplog updates (oplogExcludeCollections)
// Usage:
// settings.json = {
// "packages": {
@@ -251,11 +254,12 @@ Object.assign(OplogHandle.prototype, {
// }
// }
// }
const includeCollections = Meteor.settings?.packages?.mongo?.oplogWatchCollections;
const includeCollections = Meteor.settings?.packages?.mongo?.oplogIncludeCollections;
const excludeCollections = Meteor.settings?.packages?.mongo?.oplogExcludeCollections;
if (includeCollections?.length && excludeCollections?.length) {
throw new Error("Can't use both mongo oplog settings oplogWatchCollections and oplogExcludeCollections at the same time.");
throw new Error("Can't use both mongo oplog settings oplogIncludeCollections and oplogExcludeCollections at the same time.");
}
console.log('OplogHandle _startTailing() excludeCollections', excludeCollections);
if (excludeCollections?.length) {
oplogSelector.ns = {
$regex: oplogSelector.ns,

View File

@@ -1,4 +1,5 @@
var OplogCollection = new Mongo.Collection("oplog-" + Random.id());
var randomId = Random.id();
var OplogCollection = new Mongo.Collection("oplog-" + randomId);
Tinytest.add("mongo-livedata - oplog - cursorSupported", function (test) {
var oplogEnabled =
@@ -165,6 +166,7 @@ process.env.MONGO_OPLOG_URL && testAsyncMulti(
);
import { Mongo, MongoInternals } from 'meteor/mongo';
process.env.MONGO_OPLOG_URL && Tinytest.addAsync(
'mongo-livedata - oplog - x - implicit collection creation',
async test => {
@@ -180,6 +182,30 @@ process.env.MONGO_OPLOG_URL && Tinytest.addAsync(
},
);
process.env.MONGO_OPLOG_URL && Tinytest.addAsync(
'mongo-livedata - oplog - options.oplogExcludeCollections',
async test => {
const testCollectionName = "test-" + randomId;
if (!Meteor.settings.packages) Meteor.settings.packages = {};
if (!Meteor.settings.packages.mongo) Meteor.settings.packages.mongo = {};
// Meteor.settings.packages.mongo.oplogExcludeCollections = [testCollectionName];
const myOplogHandle = new MongoInternals.OplogHandle(process.env.MONGO_OPLOG_URL, testCollectionName);
MongoInternals.defaultRemoteCollectionDriver().mongo._setOplogHandle(myOplogHandle);
const TestCollection = new Mongo.Collection(testCollectionName);
let handle = TestCollection.find({ foo: 'bar' }).observeChanges({
added(id, fields) {
console.log('TEST added:', id, fields);
// Not working anymore! :(
}
});
await TestCollection.rawCollection().insertOne({ foo: 'bar', bla: 'blub' });
test.equal(true, true);
}
);
// Meteor.isServer && Tinytest.addAsync(
// "mongo-livedata - oplog - _onFailover",
// async function (test) {