Refectory mongo packages

- Using isomorphy async methods with the suffix Async;
- Changing tests to use async methods on client and server
- Fix tests
This commit is contained in:
Edimar Cardoso
2023-01-26 10:05:44 -03:00
parent 565d2755aa
commit 175c212290
5 changed files with 13 additions and 12 deletions

View File

@@ -311,9 +311,9 @@ export class Connection {
const queued = self._updatesForUnknownStores[name];
if (Array.isArray(queued)) {
await store.beginUpdate(queued.length, false);
queued.forEach(msg => {
store.update(msg);
});
for (const msg of queued) {
await store.update(msg);
}
await store.endUpdate();
delete self._updatesForUnknownStores[name];
}
@@ -600,7 +600,7 @@ export class Connection {
* @param {Boolean} options.returnStubValue (Client only) If true then in cases where we would have otherwise discarded the stub's return value and returned undefined, instead we go ahead and return it. Specifically, this is any time other than when (a) we are already inside a stub or (b) we are in Node and no callback was provided. Currently we require this flag to be explicitly passed to reduce the likelihood that stub return values will be confused with server return values; we may improve this in future.
* @param {Function} [asyncCallback] Optional callback; same semantics as in [`Meteor.call`](#meteor_call).
*/
apply(name, args, options, callback) {
async apply(name, args, options, callback) {
const { stubInvocation, invocation, ...stubOptions } = this._stubCall(name, EJSON.clone(args));
if (stubOptions.hasStub) {
@@ -610,7 +610,7 @@ export class Connection {
isFromCallAsync: stubOptions.isFromCallAsync,
})
) {
this._saveOriginals();
await this._saveOriginals();
}
try {
stubOptions.stubReturnValue = DDP._CurrentMethodInvocation
@@ -1171,8 +1171,9 @@ export class Connection {
if (! self._waitingForQuiescence()) {
if (self._resetStores) {
Object.values(self._stores).forEach((store) => {
store.beginUpdate(0, true);
store.endUpdate();
store.beginUpdate(0, true).finally(async () => {
await store.endUpdate();
});
});
self._resetStores = false;
}

View File

@@ -2478,7 +2478,7 @@ if (Meteor.isClient) {
// Buffer should already be flushed because of a non-update message.
// And after a flush we really want subscription field to be 112.
conn._flushBufferedWrites();
await conn._flushBufferedWrites();
test.equal((await coll.findOneAsync('aaa')).method, 222);
test.equal((await coll.findOneAsync('aaa')).subscription, 112);
});

View File

@@ -302,7 +302,7 @@ if (Meteor.isServer) {
// Tailable observe shouldn't show things that are in the initial
// contents.
self.insertAsync({x: 1});
await self.insertAsync({x: 1});
// Wait for one added call before going to the next test function.
self.expects.push(expect());

View File

@@ -202,7 +202,7 @@ _.extend(PollingObserveDriver.prototype, {
// round, mark all the writes which existed before this call as
// commmitted. (If new writes have shown up in the meantime, there'll
// already be another _pollMongo task scheduled.)
self._multiplexer.onFlush(function () {
await self._multiplexer.onFlush(function () {
_.each(writesForCycle, function (w) {
w.committed();
});

View File

@@ -2,7 +2,7 @@ Tinytest.addAsync('mongo livedata - native upsert - id type MONGO with MODIFIERS
var collName = Random.id();
var coll = new Mongo.Collection('native_upsert_'+collName, {idGeneration: 'MONGO'});
coll.insertAsync({foo: 1});
await coll.insertAsync({foo: 1});
var result = await coll.upsertAsync({foo: 1}, {$set: {foo:2}});
var updated = await coll.findOneAsync({foo: 2});
@@ -36,7 +36,7 @@ Tinytest.addAsync('mongo livedata - native upsert - id type MONGO PLAIN OBJECT u
var collName = Random.id();
var coll = new Mongo.Collection('native_upsert_'+collName, {idGeneration: 'MONGO'});
coll.insertAsync({foo: 1, baz: 42});
await coll.insertAsync({foo: 1, baz: 42});
var result = await coll.upsertAsync({foo: 1}, {bar:2});
var updated = await coll.findOneAsync({bar: 2});