Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix nondeterministic test failures on CI #251

Merged
merged 4 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading