Skip to content

Add unit tests for gladstone extension handling service. #78034

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

Merged
merged 18 commits into from
Apr 8, 2025

Conversation

CyrusNajmabadi
Copy link
Member

No description provided.

@CyrusNajmabadi CyrusNajmabadi requested a review from a team as a code owner April 7, 2025 21:52
@ghost ghost added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels Apr 7, 2025
@@ -28,7 +28,7 @@ private sealed class ExtensionFolder
/// <summary>
/// Lazily computed assembly loader for this particular folder.
/// </summary>
private readonly AsyncLazy<(IAnalyzerAssemblyLoaderInternal? assemblyLoader, Exception? extensionException)> _lazyAssemblyLoader;
private readonly AsyncLazy<(IExtensionAssemblyLoader? assemblyLoader, Exception? extensionException)> _lazyAssemblyLoader;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

had to abstract out this type so we could test the varying things it could do with mocks.

@@ -43,52 +43,16 @@ public ExtensionFolder(
_extensionMessageHandlerService = extensionMessageHandlerService;
_lazyAssemblyLoader = AsyncLazy.Create(cancellationToken =>
{
#if NET
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved to the default impl of the extension loading service.


namespace Microsoft.CodeAnalysis.Extensions;

/// <summary>
/// Factory for creating instances of extension message handlers.
/// </summary>
internal interface IExtensionMessageHandlerFactory
internal interface IExtensionMessageHandlerFactory : IWorkspaceService
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

became a workspace service so we can override it in tests with our own version ot mock out exceptions it might through without actually loading assemblies and using reflection on them.


// Don't trap the error here. We want to validate that this crosses the ServiceHub boundary and is reported as
// a real roslyn/gladstone error.
string? fatalRpcErrorMessage = null;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the general pattern is that we capture if we're getting a fatal error (indicating a bug between gladstone and us), or an 'extension exception' (a supported part of the data contracts). The tests partition these to ensure we know what we should actually be throwing exceptions internally for, vs what we should be capturing and passing along as data.

Note: 'cancellation' is tested at all layers. As that is something we should throw (and not capture as an extnesion exception) but which should also not be a fatal rpc error.

@CyrusNajmabadi CyrusNajmabadi enabled auto-merge April 7, 2025 22:25
@CyrusNajmabadi CyrusNajmabadi merged commit 6f70f70 into dotnet:main Apr 8, 2025
25 checks passed
@CyrusNajmabadi CyrusNajmabadi deleted the serviceTests branch April 8, 2025 00:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead VSCode
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants