- fix "observeChanges - tailable"

This commit is contained in:
denihs
2023-02-09 13:38:20 -04:00
parent cf4c649726
commit 62df47fdeb

View File

@@ -307,61 +307,62 @@ Tinytest.addAsync("observeChanges - unordered - enters and exits result set thro
if (Meteor.isServer) {
testAsyncMulti("observeChanges - tailable", [
function (test, expect) {
async function (test, expect) {
var self = this;
var collName = "cap_" + Random.id();
var collName = 'cap_' + Random.id();
var coll = new Mongo.Collection(collName);
coll._createCappedCollection(1000000);
await coll.createCappedCollectionAsync(1000000);
self.xs = [];
self.expects = [];
self.insert = function (fields) {
coll.insert(_.extend({ts: new MongoInternals.MongoTimestamp(0, 0)},
fields));
self.insert = async function(fields) {
await coll.insertAsync(
_.extend({ ts: new MongoInternals.MongoTimestamp(0, 0) }, fields)
);
};
// Tailable observe shouldn't show things that are in the initial
// contents.
self.insert({x: 1});
await self.insert({ x: 1 });
// Wait for one added call before going to the next test function.
self.expects.push(expect());
var cursor = coll.find({y: {$ne: 7}}, {tailable: true});
self.handle = cursor.observeChanges({
added: function (id, fields) {
var cursor = coll.find({ y: { $ne: 7 } }, { tailable: true });
self.handle = await cursor.observeChanges({
added: function(id, fields) {
self.xs.push(fields.x);
test.notEqual(self.expects.length, 0);
self.expects.pop()();
},
changed: function () {
test.fail({unexpected: "changed"});
changed: function() {
test.fail({ unexpected: 'changed' });
},
removed: function() {
test.fail({ unexpected: 'removed' });
},
removed: function () {
test.fail({unexpected: "removed"});
}
});
// Nothing happens synchronously.
test.equal(self.xs, []);
},
function (test, expect) {
async function (test, expect) {
var self = this;
// The cursors sees the first element.
test.equal(self.xs, [1]);
self.xs = [];
self.insert({x: 2, y: 3});
self.insert({x: 3, y: 7}); // filtered out by the query
self.insert({x: 4});
await self.insert({x: 2, y: 3});
await self.insert({x: 3, y: 7}); // filtered out by the query
await self.insert({x: 4});
// Expect two added calls to happen.
self.expects = [expect(), expect()];
},
function (test, expect) {
async function (test, expect) {
var self = this;
test.equal(self.xs, [2, 4]);
self.xs = [];
self.handle.stop();
self.insert({x: 5});
await self.insert({x: 5});
// XXX This timeout isn't perfect but it's pretty hard to prove that an
// event WON'T happen without something like a write fence.
Meteor.setTimeout(expect(), 1000);