DEV: Fix a presence-test flake (#27501)

This commit is contained in:
Jarek Radosz 2024-06-18 12:11:40 +02:00 committed by GitHub
parent 53b3d2f0dc
commit f904acbc85
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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"]);
});
});