From f60fc892bf401001ccc8bcc1e1ea520ed53f2e59 Mon Sep 17 00:00:00 2001 From: Ashish Reddy Podduturi Date: Tue, 18 Aug 2026 15:15:17 -0700 Subject: [PATCH] test(chat-client): give the jsdom-backed suites a realistic timeout budget The chat-client suites intermittently fail CI with "Timeout of 5000ms exceeded", on a different test each time and on whichever platform happens to be slowest. Reproduced and measured locally rather than guessed at. These tests drive the real MynahUI against jsdom, so creating a tab is several hundred milliseconds of synchronous DOM work: 1811ms and 1700ms for the two sendGenericCommand cases, 825ms and 818ms for the two openTab cases, on an idle machine. Mocha reports a synchronous test that overruns its budget as a timeout -- it compares elapsed time after the body returns, which is the `at processImmediate` frame in the CI stack traces. Under 3x CPU contention, emulating a loaded shared runner, every test slows by a consistent 4.6-7.0x. Three tests then exceed the 5s default and two more land at 70-98% of it, so which test is blamed is down to luck. That matches the observed failures exactly: `openTab > should create a new tab with welcome messages...` at 5559ms against its 5s default on Linux, and `sendGenericCommand > should create a new tab if none exits` at 8275ms against the 10s patch it already carried on Windows. The per-test `this.timeout(10000)` and `this.timeout(30000)` already in the file were earlier attempts at the same problem, applied only to whichever test had failed at the time. This replaces them with one suite-level budget per file, and extends the same to chat.test.ts, whose slowest case reaches 3.5s under load and is next in line. Verification, same 3x contention that reproduces the failure: before: 1 failing (openTab, 5559ms vs 5000ms) after: 0 failing across 3 consecutive runs, slowest test 8804-9193ms vs 30000ms Idle behaviour is unchanged: 213 passing, 1 pending, 0 failing before and after. No product code changes, and 30s still catches a genuine hang. --- chat-client/src/client/chat.test.ts | 9 ++++++++- chat-client/src/client/mynahUi.test.ts | 15 ++++++++++++--- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/chat-client/src/client/chat.test.ts b/chat-client/src/client/chat.test.ts index efd08da81d..89fef60238 100644 --- a/chat-client/src/client/chat.test.ts +++ b/chat-client/src/client/chat.test.ts @@ -30,7 +30,14 @@ import { MynahUI } from '@aws/mynah-ui' import { TabFactory } from './tabs/tabFactory' import { ChatClientAdapter } from '../contracts/chatClientAdapter' -describe('Chat', () => { +describe('Chat', function () { + /** + * Also jsdom-backed: the slowest cases here reach ~570ms idle and 3.5s under load, + * i.e. 70% of the default 5s budget, so they are the next to flake. See the note in + * mynahUi.test.ts. + */ + this.timeout(30_000) + const sandbox = sinon.createSandbox() const initialTabId = 'tab-1' let mynahUi: MynahUI diff --git a/chat-client/src/client/mynahUi.test.ts b/chat-client/src/client/mynahUi.test.ts index a69cf883c7..34ede0cb5b 100644 --- a/chat-client/src/client/mynahUi.test.ts +++ b/chat-client/src/client/mynahUi.test.ts @@ -18,7 +18,18 @@ import { ChatHistory } from './features/history' import { pairProgrammingModeOn, pairProgrammingModeOff } from './texts/pairProgramming' import { strictEqual } from 'assert' -describe('MynahUI', () => { +describe('MynahUI', function () { + /** + * These tests drive the real MynahUI against jsdom, so creating a tab performs several + * hundred milliseconds of synchronous DOM work -- up to ~1.8s for the sendGenericCommand + * cases on an idle developer machine. Mocha reports a synchronous test that overruns its + * budget as "Timeout of Nms exceeded", so on a loaded CI runner (measured 4.6-7x slower) + * the default 5s budget is exceeded and the suite fails on whichever test is unlucky. + * One generous budget for the whole suite replaces the per-test 10s/30s patches that + * were added for the same reason. + */ + this.timeout(30_000) + let messager: Messager let mynahUi: MynahUI let inboundChatApi: InboundChatApi @@ -248,7 +259,6 @@ describe('MynahUI', () => { describe('sendGenericCommand', () => { it('should create a new tab if none exits', function () { - this.timeout(10000) // Increase timeout to 10 seconds // clear create tab stub since set up process calls it twice createTabStub.resetHistory() // Stub setTimeout to execute immediately @@ -275,7 +285,6 @@ describe('MynahUI', () => { }) it('should create a new tab if current tab is loading', function () { - this.timeout(30000) // clear create tab stub since set up process calls it twice createTabStub.resetHistory() // Stub setTimeout to execute immediately