From 377543b2b3e7000950dadc99ff7011ff5e7cec44 Mon Sep 17 00:00:00 2001 From: Jake Macdonald Date: Tue, 11 Nov 2025 20:30:11 +0000 Subject: [PATCH] add retry logic to the analyze test --- pkgs/dart_mcp_server/test/test_harness.dart | 30 ++++++++----- .../test/tools/analyzer_test.dart | 43 ++++++++++--------- 2 files changed, 42 insertions(+), 31 deletions(-) diff --git a/pkgs/dart_mcp_server/test/test_harness.dart b/pkgs/dart_mcp_server/test/test_harness.dart index 0cc624dd..6c7f9d68 100644 --- a/pkgs/dart_mcp_server/test/test_harness.dart +++ b/pkgs/dart_mcp_server/test/test_harness.dart @@ -26,6 +26,21 @@ import 'package:test/test.dart'; import 'package:test_process/test_process.dart'; import 'package:unified_analytics/unified_analytics.dart'; +Future callWithRetry( + FutureOr Function() fn, { + int maxTries = 5, +}) async { + var tryCount = 0; + while (true) { + try { + return await fn(); + } catch (_) { + if (tryCount++ >= maxTries) rethrow; + } + await Future.delayed(Duration(milliseconds: 100 * tryCount)); + } +} + /// A full environment for integration testing the MCP server. /// /// - Runs the counter app at `test_fixtures/counter_app` using `flutter run`. @@ -187,17 +202,10 @@ class TestHarness { CallToolRequest request, { int maxTries = 5, bool expectError = false, - }) async { - var tryCount = 0; - while (true) { - try { - return await callTool(request, expectError: expectError); - } catch (_) { - if (tryCount++ >= maxTries) rethrow; - } - await Future.delayed(Duration(milliseconds: 100 * tryCount)); - } - } + }) => callWithRetry( + () => callTool(request, expectError: expectError), + maxTries: maxTries, + ); /// Calls [getPrompt] on the [mcpServerConnection]. Future getPrompt(GetPromptRequest request) => diff --git a/pkgs/dart_mcp_server/test/tools/analyzer_test.dart b/pkgs/dart_mcp_server/test/tools/analyzer_test.dart index 86e548f0..d31f1813 100644 --- a/pkgs/dart_mcp_server/test/tools/analyzer_test.dart +++ b/pkgs/dart_mcp_server/test/tools/analyzer_test.dart @@ -309,27 +309,30 @@ void main() { ], }, ); - final result = await testHarness.callToolWithRetry(request, maxTries: 10); - expect(result.isError, isNot(true)); - expect(result.content, hasLength(2)); - expect( - result.content, - containsAll([ - isA().having( - (t) => t.text, - 'text', - contains( - "The argument type 'String' can't be assigned to the " - "parameter type 'num'.", + // It may take a bit for the errors to show up. + await callWithRetry(() async { + final result = await testHarness.callTool(request); + expect(result.isError, isNot(true)); + expect(result.content, hasLength(2)); + expect( + result.content, + containsAll([ + isA().having( + (t) => t.text, + 'text', + contains( + "The argument type 'String' can't be assigned to the " + "parameter type 'num'.", + ), ), - ), - isA().having( - (t) => t.text, - 'text', - contains("Undefined name 'foo'"), - ), - ]), - ); + isA().having( + (t) => t.text, + 'text', + contains("Undefined name 'foo'"), + ), + ]), + ); + }, maxTries: 10); }); test('can look up symbols in a workspace', () async {