mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
trying to write the according tests :)
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user