- fix test: 'mongo-livedata - async server-side insert, MONGO | STRING'

This commit is contained in:
denihs
2023-02-14 07:49:53 -04:00
parent 2fc41f5eab
commit 712a48bce1

View File

@@ -912,20 +912,28 @@ _.each( ['STRING', 'MONGO'], function(idGeneration) {
}
);
Tinytest.addAsync("mongo-livedata - async server-side insert, " + idGeneration, function (test, onComplete) {
// Tests that insert returns before the callback runs. Relies on the fact
// that mongo does not run the callback before spinning off the event loop.
var cname = Random.id();
var coll = new Mongo.Collection(cname);
var doc = { foo: "bar" };
var x = 0;
coll.insert(doc, function (err, result) {
test.equal(err, null);
test.equal(x, 1);
onComplete();
});
x++;
});
Tinytest.addAsync(
'mongo-livedata - async server-side insert, ' + idGeneration,
async function(test, onComplete) {
// Tests that insert returns before the callback runs. Relies on the fact
// that mongo does not run the callback before spinning off the event loop.
var cname = Random.id();
var coll = new Mongo.Collection(cname);
var doc = { foo: 'bar' };
var x = 0;
let resolver;
const promise = new Promise(r => resolver = r);
coll.insertAsync(doc).then(() => {
test.equal(x, 1)
resolver();
});
x++;
await promise;
}
);
Tinytest.addAsync("mongo-livedata - async server-side update, " + idGeneration, function (test, onComplete) {
// Tests that update returns before the callback runs.