Fix mongo tests

This commit is contained in:
Edimar Cardoso
2023-01-16 10:59:53 -03:00
parent 7825255744
commit e40198cf8e

View File

@@ -292,81 +292,86 @@ Tinytest.addAsync("observeChanges - unordered - enters and exits result set thro
});
});
//TODO How to implement this test?
// if (Meteor.isServer) {
// testAsyncMulti("observeChanges - tailable", [
// async function f1(test, expect) {
// var self = this;
// var collName = "cap_" + Random.id();
// var coll = new Mongo.Collection(collName);
// await coll._createCappedCollection(1000000);
// self.xs = [];
// self.expects = [];
// self.insert = async function (fields) {
// await coll.insert(_.extend({ts: new MongoInternals.MongoTimestamp(0, 0)},
// fields));
// };
//
// // Tailable observe shouldn't show things that are in the initial
// // contents.
// 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});
// //var resolved;
// //const resultWait = new Promise(resolve => resolved = resolve);
// self.handle = await cursor.observeChanges({
// added: function (id, fields) {
// self.xs.push(fields.x);
// test.notEqual(self.expects.length, 0);
// self.expects.pop()();
// //resolved();
// },
// changed: function () {
// test.fail({unexpected: "changed"});
// },
// removed: function () {
// test.fail({unexpected: "removed"});
// }
// });
//
// // Nothing happens synchronously.
// test.equal(self.xs, []);
// //await resultWait;
// },
// async function f2(test, expect) {
// var self = this;
// const {xs} = self;
// console.log('X2', {self,xs});
// // The cursors sees the first element.
// //test.equal(self.xs, [1]); ???????
// self.xs = [];
//
// await self.insert({x: 2, y: 3});
// await self.insert({x: 3, y: 7}); // filtered out by the query
// await self.insert({x: 4});
// console.log({self});
// // Expect two added calls to happen.
// self.expects = [expect(), expect()];
// },
// // async function f3(test, expect) {
// // var self = this;
// // test.equal(self.xs, [2, 4]);
// // self.xs = [];
// // await self.handle.stop();
// //
// // 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);
// // },
// // function f4(test, expect) {
// // var self = this;
// // test.equal(self.xs, []);
// // }
// ]);
// }
// TODO How to implement this test?
if (Meteor.isServer) {
testAsyncMulti("observeChanges - tailable", [
async function f1(test, expect) {
var self = this;
var collName = "cap_" + Random.id();
var coll = new Mongo.Collection(collName);
await coll._createCappedCollection(1000000);
self.xs = [];
self.expects = [];
self.insert = async function (fields) {
await coll.insert(_.extend({ts: new MongoInternals.MongoTimestamp(0, 0)},
fields));
};
// Tailable observe shouldn't show things that are in the initial
// contents.
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 = 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"});
},
removed: function () {
test.fail({unexpected: "removed"});
}
});
// Nothing happens synchronously.
test.equal(self.xs, []);
let resolve;
const waitFor = new Promise(r => resolve = r);
Meteor.setTimeout(resolve, 100);
return waitFor;
},
async function f2(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});
// Expect two added calls to happen.
self.expects = [expect(), expect()];
let resolve;
const waitFor = new Promise(r => resolve = r);
Meteor.setTimeout(resolve, 100);
return waitFor;
},
async function f3(test, expect) {
var self = this;
test.equal(self.xs, [2, 4]);
self.xs = [];
await self.handle.stop();
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.
let resolve;
const waitFor = new Promise(r => resolve = r);
Meteor.setTimeout(resolve, 100);
return waitFor;
},
function f4(test, expect) {
var self = this;
test.equal(self.xs, []);
}
]);
}
testAsyncMulti("observeChanges - bad query", [