From 3931eeb6433f769b9baed8151f1527bfb42bccaf Mon Sep 17 00:00:00 2001 From: Mikayla Hutchinson Date: Wed, 25 Sep 2024 19:30:12 -0400 Subject: [PATCH] Attempt alternate workaround for CI race --- .../Extensions/CommandServiceExtensions.cs | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/Editor.Tests/Extensions/CommandServiceExtensions.cs b/Editor.Tests/Extensions/CommandServiceExtensions.cs index ef55e83..b2e8bf2 100644 --- a/Editor.Tests/Extensions/CommandServiceExtensions.cs +++ b/Editor.Tests/Extensions/CommandServiceExtensions.cs @@ -70,9 +70,30 @@ public static void CheckAndExecute ( LogTrace ("Session open"); RegisterTraceHandlers (session); } + // If we have a session, but it hasn't started yet, wait for it to start. + // We previously only called session.GetComputedItems to wait for the completion + // to be updated, but on slow machines, e.g. on CI, this could cause completion + // to be dismissed (TryDismissSafelyAsync) before it was even shown. + if (session is IAsyncCompletionSessionOperations sessionOperations) { + if (!sessionOperations.IsStarted) { + if (EnableDebugTrace) { + LogTrace ("Session is not started"); + } + // wait up to 2.5 seconds in 25ms intervals + for (int i = 0; i < 100; i++) { + if (sessionOperations.IsStarted) { + if (EnableDebugTrace) { + LogTrace ("Session started after {i * 25}ms"); + } + break; + } + Thread.Sleep (25); + } + } + } + //ensure the computation is completed before we continue typing session.GetComputedItems (CancellationToken.None); - LogTrace ("Session open"); } } else{ LogTrace ("Session not open");