Skip to content

Commit

Permalink
Merge pull request #251 from mhutch/fix-nondeterministic-ci-test-failure
Browse files Browse the repository at this point in the history
Fix nondeterministic test failures on CI
  • Loading branch information
mhutch authored Sep 26, 2024
2 parents 7598ca4 + 317b3e2 commit 06a7118
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,16 @@ protected override MSBuildCompletionContext CreateTriggerContext (IAsyncCompleti

protected override Task<IList<CompletionItem>> GetElementCompletionsAsync (MSBuildCompletionContext context, bool includeBracket, CancellationToken token)
{
if (EnableDebugTrace) {
LogTrace ($"Entered GetElementCompletionsAsync");
}
var doc = context.Document;

var nodePath = context.NodePath;
if (!CompletionHelpers.TryGetElementSyntaxForElementCompletion(nodePath, out MSBuildElementSyntax languageElement, out string elementName)) {
if (EnableDebugTrace) {
LogTrace ($"Exited GetElementCompletionsAsync with no syntax");
}
return TaskCompleted (null);
}

Expand All @@ -80,6 +86,9 @@ protected override Task<IList<CompletionItem>> GetElementCompletionsAsync (MSBui
items.Add (c);
}

if (EnableDebugTrace) {
LogTrace ($"Exited GetElementCompletionsAsync with {items.Count} items");
}
return TaskCompleted (items);
}

Expand Down
34 changes: 20 additions & 14 deletions MonoDevelop.MSBuild.Tests.Editor/Completion/MSBuildCommitTests.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
// 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;
using System.Threading.Tasks;

using Microsoft.VisualStudio.Text.Editor.Commanding;

using MonoDevelop.Xml.Editor.Tests.Extensions;

using NUnit.Framework;
Expand All @@ -15,18 +13,26 @@ namespace MonoDevelop.MSBuild.Tests.Editor.Completion
[TestFixture]
public class MSBuildCommitTests : MSBuildEditorTest
{
Task TestTypeCommands (string filename, string before, string typeChars, string after)
async Task TestTypeCommands (string filename, string before, string typeChars, string after)
{
return this.TestCommands (
before,
after,
[ (s) => s.Type (typeChars) ],
filename: filename,
initialize: (tv) => {
tv.Options.SetOptionValue ("BraceCompletion/Enabled", true);
return Task.CompletedTask;
}
);
//CommandServiceExtensions.EnableDebugTrace = true;
//MSBuildCompletionSource.EnableDebugTrace = true;
//try {
await this.TestCommands (
before,
after,
EditorAction.Type (typeChars),
filename: filename,
initialize: async (tv) => {
tv.Options.SetOptionValue ("BraceCompletion/Enabled", true);
// ensure we have an initial parse before triggering completion
await Catalog.MSBuildParserProvider.GetParser (tv.TextBuffer).GetOrProcessAsync (tv.TextBuffer.CurrentSnapshot, CancellationToken.None);
}
);
//} finally {
// CommandServiceExtensions.EnableDebugTrace = false;
// MSBuildCompletionSource.EnableDebugTrace = false;
//}
}

[Test]
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 06a7118

Please sign in to comment.