Skip to content

Commit

Permalink
Yield UI thread between editor commands in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mhutch committed Sep 26, 2024
1 parent 9212bb7 commit 6ba2032
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
using System.Threading.Tasks;

using Microsoft.VisualStudio.Text.Editor.Commanding;
using MonoDevelop.MSBuild.Editor.Completion;

using MonoDevelop.Xml.Editor.Tests.Extensions;

using NUnit.Framework;
Expand All @@ -24,7 +20,7 @@ async Task TestTypeCommands (string filename, string before, string typeChars, s
await this.TestCommands (
before,
after,
[ (s) => s.Type (typeChars) ],
EditorAction.Type (typeChars),
filename: filename,
initialize: (tv) => {
tv.Options.SetOptionValue ("BraceCompletion/Enabled", true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,13 @@ public static async Task TestCodeActionContext (
// the refactoring may have left multiple selections sp the user can e.g. type a new name for an extracted property
await test.Catalog.JoinableTaskContext.Factory.SwitchToMainThreadAsync (default);
var commandService = test.Catalog.CommandServiceFactory.GetService (ctx.TextView);
commandService.Type (typeText);

foreach(var editorAction in EditorAction.Type (typeText)) {
editorAction (commandService);
// yield to let things catch up
// and so we don't block the UI thread between the commands
await Task.Delay (20);
}

Assert.That (
ctx.TextBuffer.CurrentSnapshot.GetText (),
Expand Down

0 comments on commit 6ba2032

Please sign in to comment.