Skip to content

Commit 06a7118

Browse files
authored
Merge pull request #251 from mhutch/fix-nondeterministic-ci-test-failure
Fix nondeterministic test failures on CI
2 parents 7598ca4 + 317b3e2 commit 06a7118

File tree

4 files changed

+37
-16
lines changed

4 files changed

+37
-16
lines changed

MonoDevelop.MSBuild.Editor/Completion/MSBuildCompletionSource.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,16 @@ protected override MSBuildCompletionContext CreateTriggerContext (IAsyncCompleti
5656

5757
protected override Task<IList<CompletionItem>> GetElementCompletionsAsync (MSBuildCompletionContext context, bool includeBracket, CancellationToken token)
5858
{
59+
if (EnableDebugTrace) {
60+
LogTrace ($"Entered GetElementCompletionsAsync");
61+
}
5962
var doc = context.Document;
6063

6164
var nodePath = context.NodePath;
6265
if (!CompletionHelpers.TryGetElementSyntaxForElementCompletion(nodePath, out MSBuildElementSyntax languageElement, out string elementName)) {
66+
if (EnableDebugTrace) {
67+
LogTrace ($"Exited GetElementCompletionsAsync with no syntax");
68+
}
6369
return TaskCompleted (null);
6470
}
6571

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

89+
if (EnableDebugTrace) {
90+
LogTrace ($"Exited GetElementCompletionsAsync with {items.Count} items");
91+
}
8392
return TaskCompleted (items);
8493
}
8594

MonoDevelop.MSBuild.Tests.Editor/Completion/MSBuildCommitTests.cs

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
// Copyright (c) Microsoft. All rights reserved.
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

4-
using System;
4+
using System.Threading;
55
using System.Threading.Tasks;
66

7-
using Microsoft.VisualStudio.Text.Editor.Commanding;
8-
97
using MonoDevelop.Xml.Editor.Tests.Extensions;
108

119
using NUnit.Framework;
@@ -15,18 +13,26 @@ namespace MonoDevelop.MSBuild.Tests.Editor.Completion
1513
[TestFixture]
1614
public class MSBuildCommitTests : MSBuildEditorTest
1715
{
18-
Task TestTypeCommands (string filename, string before, string typeChars, string after)
16+
async Task TestTypeCommands (string filename, string before, string typeChars, string after)
1917
{
20-
return this.TestCommands (
21-
before,
22-
after,
23-
[ (s) => s.Type (typeChars) ],
24-
filename: filename,
25-
initialize: (tv) => {
26-
tv.Options.SetOptionValue ("BraceCompletion/Enabled", true);
27-
return Task.CompletedTask;
28-
}
29-
);
18+
//CommandServiceExtensions.EnableDebugTrace = true;
19+
//MSBuildCompletionSource.EnableDebugTrace = true;
20+
//try {
21+
await this.TestCommands (
22+
before,
23+
after,
24+
EditorAction.Type (typeChars),
25+
filename: filename,
26+
initialize: async (tv) => {
27+
tv.Options.SetOptionValue ("BraceCompletion/Enabled", true);
28+
// ensure we have an initial parse before triggering completion
29+
await Catalog.MSBuildParserProvider.GetParser (tv.TextBuffer).GetOrProcessAsync (tv.TextBuffer.CurrentSnapshot, CancellationToken.None);
30+
}
31+
);
32+
//} finally {
33+
// CommandServiceExtensions.EnableDebugTrace = false;
34+
// MSBuildCompletionSource.EnableDebugTrace = false;
35+
//}
3036
}
3137

3238
[Test]

MonoDevelop.MSBuild.Tests.Editor/Refactorings/MSBuildEditorTestExtensions.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,13 @@ public static async Task TestCodeActionContext (
224224
// the refactoring may have left multiple selections sp the user can e.g. type a new name for an extracted property
225225
await test.Catalog.JoinableTaskContext.Factory.SwitchToMainThreadAsync (default);
226226
var commandService = test.Catalog.CommandServiceFactory.GetService (ctx.TextView);
227-
commandService.Type (typeText);
227+
228+
foreach(var editorAction in EditorAction.Type (typeText)) {
229+
editorAction (commandService);
230+
// yield to let things catch up
231+
// and so we don't block the UI thread between the commands
232+
await Task.Delay (20);
233+
}
228234

229235
Assert.That (
230236
ctx.TextBuffer.CurrentSnapshot.GetText (),

0 commit comments

Comments
 (0)