mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
fix and add new test case for unblocking mechanism
This commit is contained in:
@@ -20,7 +20,7 @@ export const loadAsyncStubHelpers = () => {
|
||||
|
||||
queue = queue.finally(() => {
|
||||
fn(resolve, reject);
|
||||
return promise;
|
||||
return promise.stubPromise;
|
||||
});
|
||||
|
||||
promise.finally(() => {
|
||||
@@ -95,13 +95,14 @@ export const loadAsyncStubHelpers = () => {
|
||||
const applyAsyncPromise = oldApplyAsync.apply(this, args);
|
||||
stubPromiseResolver(applyAsyncPromise.stubPromise);
|
||||
serverPromiseResolver(applyAsyncPromise.serverPromise);
|
||||
applyAsyncPromise.stubPromise.finally(() => {
|
||||
finished = true;
|
||||
});
|
||||
applyAsyncPromise
|
||||
.then((result) => {
|
||||
finished = true;
|
||||
resolve(result);
|
||||
})
|
||||
.catch((err) => {
|
||||
finished = true;
|
||||
reject(err);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -320,3 +320,34 @@ Tinytest.addAsync(
|
||||
test.equal(serverEvents, ["server-only-sync", "publication"]);
|
||||
}
|
||||
);
|
||||
|
||||
Tinytest.addAsync(
|
||||
"method interaction with unblocking mechanism",
|
||||
async function (test) {
|
||||
await Meteor.callAsync("getAndResetEvents");
|
||||
|
||||
Meteor.callAsync("unblockedMethod", { delay: 200 }); // unblock + sleep for 20 milliseconds
|
||||
Meteor.callAsync("blockingMethod"); // run straight + block
|
||||
|
||||
let serverEvents = await Meteor.callAsync("getAndResetEvents");
|
||||
|
||||
test.equal(
|
||||
serverEvents,
|
||||
["unblock start", "blockingMethod"],
|
||||
"should have started the unblock method and the block method straight"
|
||||
);
|
||||
|
||||
return new Promise((resolve) =>
|
||||
setTimeout(async () => {
|
||||
serverEvents = await Meteor.callAsync("getAndResetEvents");
|
||||
test.equal(
|
||||
serverEvents,
|
||||
["unblock end"],
|
||||
"should have ended the unblock method as sleep finished"
|
||||
);
|
||||
|
||||
resolve();
|
||||
}, 400)
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
@@ -40,7 +40,16 @@ Meteor.methods({
|
||||
events.push('callAsyncStubFromAsyncStub');
|
||||
|
||||
return 'server result';
|
||||
}
|
||||
},
|
||||
async 'unblockedMethod'({ delay }) {
|
||||
events.push('unblock start');
|
||||
this.unblock();
|
||||
await Meteor._sleepForMs(delay);
|
||||
events.push('unblock end');
|
||||
},
|
||||
'blockingMethod'() {
|
||||
events.push('blockingMethod');
|
||||
},
|
||||
});
|
||||
|
||||
Meteor.publish("simple-publication", function () {
|
||||
|
||||
@@ -1201,30 +1201,6 @@ testAsyncMulti('livedata - methods with nested stubs', [
|
||||
},
|
||||
]);
|
||||
|
||||
Tinytest.addAsync('livedata - method interaction with unblocking mechanism', async function(test) {
|
||||
let serverEvents = [];
|
||||
|
||||
// server-only methods
|
||||
Meteor.methods({
|
||||
[`unblockedMethod${test.runId()}`]: async function() {
|
||||
serverEvents.push('unblock start');
|
||||
this.unblock();
|
||||
await Meteor._sleepForMs(2000);
|
||||
serverEvents.push('unblock end')
|
||||
},
|
||||
[`blockingMethod${test.runId()}`]: async function() {
|
||||
serverEvents.push('blockingMethod');
|
||||
}
|
||||
});
|
||||
|
||||
Meteor.callAsync(`unblockedMethod${test.runId()}`);
|
||||
Meteor.callAsync(`blockingMethod${test.runId()}`);
|
||||
|
||||
if (Meteor.isServer) {
|
||||
test.equal(serverEvents, ['unblock start', 'blockingMethod']);
|
||||
}
|
||||
});
|
||||
|
||||
// TODO [FIBERS] - check if this still makes sense to have
|
||||
|
||||
// Tinytest.addAsync('livedata - isAsync call', async function (test) {
|
||||
|
||||
Reference in New Issue
Block a user