From f904acbc8554d9e13a67237d7e3563a71f06d118 Mon Sep 17 00:00:00 2001 From: Jarek Radosz Date: Tue, 18 Jun 2024 12:11:40 +0200 Subject: [PATCH] DEV: Fix a presence-test flake (#27501) --- .../tests/unit/services/presence-test.js | 29 +++++++++---------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/app/assets/javascripts/discourse/tests/unit/services/presence-test.js b/app/assets/javascripts/discourse/tests/unit/services/presence-test.js index 50eb24c6471..dc4ee026a7f 100644 --- a/app/assets/javascripts/discourse/tests/unit/services/presence-test.js +++ b/app/assets/javascripts/discourse/tests/unit/services/presence-test.js @@ -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"]); }); });