From 2aa1d742865245fc5f7a394b72519759547cd80b Mon Sep 17 00:00:00 2001 From: Sandy Tao Date: Thu, 16 Oct 2025 13:53:08 -0700 Subject: [PATCH] fix(test): deflake flicker integration test (#11308) --- integration-tests/flicker.test.ts | 4 ++-- integration-tests/test-helper.ts | 28 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/integration-tests/flicker.test.ts b/integration-tests/flicker.test.ts index 6b0665db65..730cde86f3 100644 --- a/integration-tests/flicker.test.ts +++ b/integration-tests/flicker.test.ts @@ -20,8 +20,8 @@ describe('Flicker Detector', () => { const hasUserPromptEvent = await rig.waitForTelemetryEvent('user_prompt'); expect(hasUserPromptEvent).toBe(true); - const sessionCountMetric = rig.readMetric('session.count'); - expect(sessionCountMetric).not.toBeNull(); + const hasSessionCountMetric = await rig.waitForMetric('session.count'); + expect(hasSessionCountMetric).toBe(true); // We expect NO flicker event to be found. const flickerMetric = rig.readMetric('ui.flicker.count'); diff --git a/integration-tests/test-helper.ts b/integration-tests/test-helper.ts index 33bb499256..2ac1a35ba1 100644 --- a/integration-tests/test-helper.ts +++ b/integration-tests/test-helper.ts @@ -910,6 +910,34 @@ export class TestRig { return apiRequests.pop() || null; } + async waitForMetric(metricName: string, timeout?: number) { + await this.waitForTelemetryReady(); + + const fullName = metricName.startsWith('gemini_cli.') + ? metricName + : `gemini_cli.${metricName}`; + + return poll( + () => { + const logs = this._readAndParseTelemetryLog(); + for (const logData of logs) { + if (logData.scopeMetrics) { + for (const scopeMetric of logData.scopeMetrics) { + for (const metric of scopeMetric.metrics) { + if (metric.descriptor.name === fullName) { + return true; + } + } + } + } + } + return false; + }, + timeout ?? getDefaultTimeout(), + 100, + ); + } + readMetric(metricName: string): Record | null { const logs = this._readAndParseTelemetryLog(); for (const logData of logs) {