Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix an issue with methods interacting with unblocking mechanisms #13055

Merged
merged 9 commits into from
Mar 12, 2024
7 changes: 4 additions & 3 deletions packages/ddp-client/client/queueStubsHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const loadAsyncStubHelpers = () => {

queue = queue.finally(() => {
fn(resolve, reject);
return promise;
return promise.stubPromise;
nachocodoner marked this conversation as resolved.
Show resolved Hide resolved
});

promise.finally(() => {
Expand Down Expand Up @@ -95,13 +95,14 @@ export const loadAsyncStubHelpers = () => {
const applyAsyncPromise = oldApplyAsync.apply(this, args);
stubPromiseResolver(applyAsyncPromise.stubPromise);
serverPromiseResolver(applyAsyncPromise.serverPromise);
applyAsyncPromise.stubPromise.finally(() => {
nachocodoner marked this conversation as resolved.
Show resolved Hide resolved
finished = true;
});
applyAsyncPromise
.then((result) => {
finished = true;
resolve(result);
})
.catch((err) => {
finished = true;
reject(err);
});
});
Expand Down
30 changes: 30 additions & 0 deletions packages/ddp-client/test/async_stubs/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,3 +320,33 @@ 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 200 milliseconds
Meteor.callAsync("blockingMethod"); // run straight + block
nachocodoner marked this conversation as resolved.
Show resolved Hide resolved

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)
);
}
);
11 changes: 10 additions & 1 deletion packages/ddp-client/test/async_stubs/server_setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down