DEV: Fix a presence-test flake (#27501)
This commit is contained in:
parent
53b3d2f0dc
commit
f904acbc85
app/assets/javascripts/discourse/tests/unit/services
|
@ -37,11 +37,10 @@ module("Unit | Service | presence | subscribing", function (hooks) {
|
||||||
setupTest(hooks);
|
setupTest(hooks);
|
||||||
|
|
||||||
hooks.beforeEach(function () {
|
hooks.beforeEach(function () {
|
||||||
pretender.get("/presence/get", async (request) => {
|
pretender.get("/presence/get", (request) => {
|
||||||
const channels = request.queryParams.channels;
|
|
||||||
const result = {};
|
const result = {};
|
||||||
|
|
||||||
channels.forEach((c) => {
|
request.queryParams.channels.forEach((c) => {
|
||||||
if (c.startsWith("/test/")) {
|
if (c.startsWith("/test/")) {
|
||||||
result[c] = {
|
result[c] = {
|
||||||
count: 3,
|
count: 3,
|
||||||
|
@ -267,11 +266,7 @@ module("Unit | Service | presence | entering and leaving", function (hooks) {
|
||||||
const result = {};
|
const result = {};
|
||||||
const channelsRequested = body.getAll("present_channels[]");
|
const channelsRequested = body.getAll("present_channels[]");
|
||||||
channelsRequested.forEach((c) => {
|
channelsRequested.forEach((c) => {
|
||||||
if (c.startsWith("/test/")) {
|
result[c] = c.startsWith("/test/");
|
||||||
result[c] = true;
|
|
||||||
} else {
|
|
||||||
result[c] = false;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return response(result);
|
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) {
|
test("don't spam requests when server returns 429", async function (assert) {
|
||||||
const done = assert.async();
|
|
||||||
let requestCount = 0;
|
let requestCount = 0;
|
||||||
pretender.post("/presence/update", async () => {
|
pretender.post("/presence/update", () => {
|
||||||
requestCount++;
|
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");
|
const presenceService = getOwner(this).lookup("service:presence");
|
||||||
presenceService.currentUser = currentUser();
|
presenceService.currentUser = currentUser();
|
||||||
const channel = presenceService.getChannel("/test/ch1");
|
const channel = presenceService.getChannel("/test/ch1");
|
||||||
|
|
||||||
setTimeout(function () {
|
setTimeout(() => {
|
||||||
assert.strictEqual(requestCount, 1);
|
assert.strictEqual(requestCount, 1);
|
||||||
done();
|
assert.step("request");
|
||||||
}, 500);
|
}, 500);
|
||||||
|
|
||||||
channel.enter();
|
await channel.enter();
|
||||||
|
assert.verifySteps(["request"]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue