From 26a04b29f308e7f2c6ac3232ff1d5f97554e1305 Mon Sep 17 00:00:00 2001 From: Haitao Pan Date: Thu, 4 Jun 2026 06:55:41 +0800 Subject: [PATCH] test: stabilize OpenClaw gateway active slot regression --- .../assistant_execution_target_test.dart | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/test/runtime/assistant_execution_target_test.dart b/test/runtime/assistant_execution_target_test.dart index 983cdd2e..42fed125 100644 --- a/test/runtime/assistant_execution_target_test.dart +++ b/test/runtime/assistant_execution_target_test.dart @@ -3592,7 +3592,7 @@ void main() { controller.assistantSessionHasPendingRun('openclaw-failed-task'), isFalse, ); - expect(controller.openClawGatewayActiveTasksInternal, 0); + await _waitForOpenClawActiveTaskCount(controller, 0); expect( controller .requireTaskThreadForSessionInternal('openclaw-failed-task') @@ -3615,7 +3615,7 @@ void main() { 'openclaw-second-task', ); await secondSubmitFuture; - expect(controller.openClawGatewayActiveTasksInternal, 0); + await _waitForOpenClawActiveTaskCount(controller, 0); expect( controller.chatMessages.map((message) => message.text), contains('second task completed'), @@ -4165,6 +4165,22 @@ Future _waitForThreadLastResultCode( ); } +Future _waitForOpenClawActiveTaskCount( + AppController controller, + int expectedCount, +) async { + final deadline = DateTime.now().add(const Duration(seconds: 15)); + while (DateTime.now().isBefore(deadline)) { + if (controller.openClawGatewayActiveTasksInternal == expectedCount) { + return; + } + await Future.delayed(const Duration(milliseconds: 10)); + } + throw StateError( + 'Timed out waiting for OpenClaw active task count $expectedCount. Current count: ${controller.openClawGatewayActiveTasksInternal}.', + ); +} + class _RecordingGoTaskServiceClient implements GoTaskServiceClient { int executeCount = 0; final List requests = [];