Skip to content

Commit

Permalink
Move MEF error detection to a test, and add some known current except…
Browse files Browse the repository at this point in the history
…ions (#9965)

This fixes the integration test build
  • Loading branch information
davidwengier authored Feb 21, 2024
2 parents 7a020fd + f732803 commit a76f73b
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ public override async Task InitializeAsync()
EnsureLSPEditorEnabled();
await EnsureTextViewRolesAsync(ControlledHangMitigatingCancellationToken);
await EnsureExtensionInstalledAsync(ControlledHangMitigatingCancellationToken);
EnsureMEFCompositionSuccessForRazor();

await TestServices.Editor.PlaceCaretAsync("</PageTitle>", charsOffset: 1, ControlledHangMitigatingCancellationToken);

Expand Down Expand Up @@ -152,31 +151,6 @@ private static void EnsureLSPEditorEnabled()
Assert.AreEqual(false, useLegacyEditor, "Expected the Legacy Razor Editor to be disabled, but it was enabled");
}

private static void EnsureMEFCompositionSuccessForRazor()
{
var hiveDirectory = VisualStudioLogging.GetHiveDirectory();
var cmcPath = Path.Combine(hiveDirectory, "ComponentModelCache");
if (!Directory.Exists(cmcPath))
{
throw new InvalidOperationException("ComponentModelCache directory doesn't exist");
}

var mefErrorFile = Path.Combine(cmcPath, "Microsoft.VisualStudio.Default.err");
if (!File.Exists(mefErrorFile))
{
throw new InvalidOperationException("Expected ComponentModelCache error file to exist");
}

var txt = File.ReadAllText(mefErrorFile);
const string Separator = "----------- Used assemblies -----------";
var content = txt.Split(new string[] { Separator }, StringSplitOptions.RemoveEmptyEntries);
var errors = content[0];
if (errors.Contains("Razor"))
{
throw new InvalidOperationException($"Razor errors detected in MEF cache: {errors}");
}
}

private async Task EnsureTextViewRolesAsync(CancellationToken cancellationToken)
{
var textView = await TestServices.Editor.GetActiveTextViewAsync(cancellationToken);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT license. See License.txt in the project root for license information.

using System.IO;
using System.Text;
using Xunit;
using Xunit.Abstractions;

namespace Microsoft.VisualStudio.Razor.IntegrationTests;

public class MEFComponentTests(ITestOutputHelper testOutputHelper) : AbstractRazorEditorTest(testOutputHelper)
{
[IdeFact]
public static void EnsureCompositionCreation()
{
var hiveDirectory = VisualStudioLogging.GetHiveDirectory();
var cmcPath = Path.Combine(hiveDirectory, "ComponentModelCache");

Assert.True(Directory.Exists(cmcPath), "ComponentModelCache directory doesn't exist");

var mefErrorFile = Path.Combine(cmcPath, "Microsoft.VisualStudio.Default.err");

Assert.True(File.Exists(mefErrorFile), "Expected ComponentModelCache error file to exist");

var section = new StringBuilder();
foreach (var line in File.ReadLines(mefErrorFile))
{
// Individual errors are separated by a blank lines, or with an "Error #" header
if (line.StartsWith("Error #") ||
string.IsNullOrWhiteSpace(line))
{
var error = section.ToString();
section.Clear();

if (error.Contains("Razor"))
{
Assert.True(IsAllowedFailure(error), "Unexpected MEF failure: " + line);
}
}
else if (line.Equals("----------- Used assemblies -----------"))
{
// Finished processing errors
break;
}
else
{
section.AppendLine(line);
}
}
}

private static bool IsAllowedFailure(string error)
{
return
// We have a little issue with LiveShare at the moment. Doesn't seem to affect user scenarios
error.Contains("Microsoft.VisualStudio.LiveShare.Razor.LiveShareProjectCapabilityResolver") ||
error.Contains("Microsoft.VisualStudio.LiveShare.Razor.Guest.GuestProjectPathProvider") ||
error.Contains("Microsoft.VisualStudio.LiveShare.Razor.Guest.LiveShareSessionAccessor");
}
}

0 comments on commit a76f73b

Please sign in to comment.