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");