mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 09:42:07 +08:00
DEV: Fix a presence-test flake (#27501)
This commit is contained in:
parent
53b3d2f0dc
commit
f904acbc85
|
@ -37,11 +37,10 @@ module("Unit | Service | presence | subscribing", function (hooks) {
|
|||
setupTest(hooks);
|
||||
|
||||
hooks.beforeEach(function () {
|
||||
pretender.get("/presence/get", async (request) => {
|
||||
const channels = request.queryParams.channels;
|
||||
pretender.get("/presence/get", (request) => {
|
||||
const result = {};
|
||||
|
||||
channels.forEach((c) => {
|
||||
request.queryParams.channels.forEach((c) => {
|
||||
if (c.startsWith("/test/")) {
|
||||
result[c] = {
|
||||
count: 3,
|
||||
|
@ -267,11 +266,7 @@ module("Unit | Service | presence | entering and leaving", function (hooks) {
|
|||
const result = {};
|
||||
const channelsRequested = body.getAll("present_channels[]");
|
||||
channelsRequested.forEach((c) => {
|
||||
if (c.startsWith("/test/")) {
|
||||
result[c] = true;
|
||||
} else {
|
||||
result[c] = false;
|
||||
}
|
||||
result[c] = c.startsWith("/test/");
|
||||
});
|
||||
|
||||
return response(result);
|
||||
|
@ -515,23 +510,27 @@ module("Unit | Service | presence | entering and leaving", function (hooks) {
|
|||
);
|
||||
});
|
||||
|
||||
test("don't spam requests when server returns 429", function (assert) {
|
||||
const done = assert.async();
|
||||
test("don't spam requests when server returns 429", async function (assert) {
|
||||
let requestCount = 0;
|
||||
pretender.post("/presence/update", async () => {
|
||||
pretender.post("/presence/update", () => {
|
||||
requestCount++;
|
||||
return response(429, { extras: { wait_seconds: 2 } });
|
||||
if (requestCount === 1) {
|
||||
return response(429, { extras: { wait_seconds: 2 } });
|
||||
} else {
|
||||
return response({});
|
||||
}
|
||||
});
|
||||
|
||||
const presenceService = getOwner(this).lookup("service:presence");
|
||||
presenceService.currentUser = currentUser();
|
||||
const channel = presenceService.getChannel("/test/ch1");
|
||||
|
||||
setTimeout(function () {
|
||||
setTimeout(() => {
|
||||
assert.strictEqual(requestCount, 1);
|
||||
done();
|
||||
assert.step("request");
|
||||
}, 500);
|
||||
|
||||
channel.enter();
|
||||
await channel.enter();
|
||||
assert.verifySteps(["request"]);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue
Block a user