From f0993d8b46888ba0f6a573082c9f490837bf496a Mon Sep 17 00:00:00 2001 From: Rekkonnect Date: Sat, 10 Aug 2024 12:58:46 +0300 Subject: [PATCH] Include the large source test --- Syndiesis.Tests/BaseProjectCodeTests.cs | 16 +++++- .../NodeViewDetailsHandlerTests.cs | 56 +++++++++---------- .../ProjectSourceProviderGetter.cs | 10 ++++ .../NodeDetailsViewData.cs | 5 +- Syndiesis/ProjectSourceProvider.cs | 12 +--- Syndiesis/ProjectSourceProviderGetter.cs | 10 ++++ 6 files changed, 68 insertions(+), 41 deletions(-) create mode 100644 Syndiesis.Tests/ProjectSourceProviderGetter.cs create mode 100644 Syndiesis/ProjectSourceProviderGetter.cs diff --git a/Syndiesis.Tests/BaseProjectCodeTests.cs b/Syndiesis.Tests/BaseProjectCodeTests.cs index b422740..b59d538 100644 --- a/Syndiesis.Tests/BaseProjectCodeTests.cs +++ b/Syndiesis.Tests/BaseProjectCodeTests.cs @@ -7,11 +7,23 @@ namespace Syndiesis.Tests; public abstract class BaseProjectCodeTests { protected static readonly ProjectSourceProvider SourceProvider - = ProjectSourceProvider.Get(); + = Syndiesis.ProjectSourceProviderGetter.Get(); - protected static readonly ImmutableArray FilesToTest + protected static readonly ProjectSourceProvider TestSourceProvider + = Syndiesis.Tests.ProjectSourceProviderGetter.Get(); + + protected static readonly ImmutableArray MainFilesToTest = SourceProvider.GetFilePaths(); + protected static readonly ImmutableArray TestFilesToTest + = TestSourceProvider.GetFilePaths(); + + protected static readonly ImmutableArray FilesToTest = + [ + .. MainFilesToTest, + .. TestFilesToTest, + ]; + [Test] public async Task TestAllFilesIndependently() { diff --git a/Syndiesis.Tests/NodeViewDetailsHandlerTests.cs b/Syndiesis.Tests/NodeViewDetailsHandlerTests.cs index bc72b06..d17108c 100644 --- a/Syndiesis.Tests/NodeViewDetailsHandlerTests.cs +++ b/Syndiesis.Tests/NodeViewDetailsHandlerTests.cs @@ -1,6 +1,8 @@ -using Microsoft.CodeAnalysis; +using Garyon.Extensions; +using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.Text; using Syndiesis.Core; +using Syndiesis.Utilities; namespace Syndiesis.Tests; @@ -18,16 +20,29 @@ protected override async Task TestSource(string text) private static async Task TestEntireHybridCompilationTree( HybridSingleTreeCompilationSource hybridCompilation) { - var tree = hybridCompilation.CurrentSource.Tree; - Assert.That(tree, Is.Not.Null); - var root = await tree.GetRootAsync(); - Assert.That(root, Is.Not.Null); + var profiling = new SimpleProfiling(); + int nodeCount = 0; + int length = 0; + using (var _ = profiling.BeginProcess()) + { + var tree = hybridCompilation.CurrentSource.Tree; + Assert.That(tree, Is.Not.Null); + var root = await tree.GetRootAsync(); + Assert.That(root, Is.Not.Null); + length = root.FullSpan.Length; + + var nodes = root.DescendantNodesAndSelf(descendIntoTrivia: true) + .ToList(); + nodeCount = nodes.Count; + await Parallel.ForEachAsync( + nodes, + TestNodeLocal); + } - var nodes = root.DescendantNodesAndSelf(descendIntoTrivia: true) - .ToList(); - await Parallel.ForEachAsync( - nodes, - TestNodeLocal); + var seconds = profiling.SnapshotResults!.Time.TotalSeconds; + TestContext.Progress.WriteLine($""" + Finished testing all {nodeCount} nodes from {length} characters in {seconds:N3}s + """); async ValueTask TestNodeLocal(SyntaxNode node, CancellationToken cancellationToken) { @@ -55,6 +70,7 @@ private static async Task TestNode( { Assert.That(rootNode?.FullSpan, Is.EqualTo(node.FullSpan)); } + } private static async Task TestExecutingResult( @@ -68,26 +84,8 @@ private static async Task TestExecutingResult( var result = execution.ExecuteCore(default); Assert.That(result, Is.Not.Null); - bool allSuccessful = await result.AwaitAllLoaded(); + bool allSuccessful = await result.AwaitAllLoaded(TimeSpan.FromMilliseconds(45)); Assert.That(allSuccessful, Is.True); return execution; } - - [Test] - public async Task TestAllFilesWithFlow() - { - TestContext.Progress.WriteLine( - "Began testing the node view data analysis on all files sequentially, this will take some more time."); - - var hybridCompilation = new HybridSingleTreeCompilationSource(); - - foreach (var file in FilesToTest) - { - var text = await File.ReadAllTextAsync(file.FullName); - hybridCompilation.SetSource(text, default); - await TestEntireHybridCompilationTree(hybridCompilation); - - TestContext.Progress.WriteLine($"Processed file {file.FullName}"); - } - } } diff --git a/Syndiesis.Tests/ProjectSourceProviderGetter.cs b/Syndiesis.Tests/ProjectSourceProviderGetter.cs new file mode 100644 index 0000000..fb5f509 --- /dev/null +++ b/Syndiesis.Tests/ProjectSourceProviderGetter.cs @@ -0,0 +1,10 @@ +namespace Syndiesis.Tests; + +public static class ProjectSourceProviderGetter +{ + public static ProjectSourceProvider Get() + { + var thisPath = ProjectSourceProvider.CallerFilePath(); + return new(thisPath); + } +} diff --git a/Syndiesis/Controls/AnalysisVisualization/NodeDetailsViewData.cs b/Syndiesis/Controls/AnalysisVisualization/NodeDetailsViewData.cs index 8adb590..9355a69 100644 --- a/Syndiesis/Controls/AnalysisVisualization/NodeDetailsViewData.cs +++ b/Syndiesis/Controls/AnalysisVisualization/NodeDetailsViewData.cs @@ -1,5 +1,6 @@ using Garyon.Functions; using Syndiesis.Core.DisplayAnalysis; +using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; @@ -40,7 +41,7 @@ SemanticModelSection SemanticModel ]; } - public async Task AwaitAllLoaded() + public async Task AwaitAllLoaded(TimeSpan expectedDelay = default) { var nodeLoaders = AllNodes() .Select(s => s.NodeLoader) @@ -48,6 +49,8 @@ public async Task AwaitAllLoaded() .ToList() ; + await Task.Delay(expectedDelay); + await Task.WhenAll(nodeLoaders!); return nodeLoaders.All(l => l!.IsCompletedSuccessfully); } diff --git a/Syndiesis/ProjectSourceProvider.cs b/Syndiesis/ProjectSourceProvider.cs index f27bb12..259be24 100644 --- a/Syndiesis/ProjectSourceProvider.cs +++ b/Syndiesis/ProjectSourceProvider.cs @@ -4,10 +4,10 @@ namespace Syndiesis; -public sealed class ProjectSourceProvider(string? callerFilePath) +public class ProjectSourceProvider(string? callerFilePath) { private readonly string? _callerFilePath = callerFilePath; - + public ImmutableArray GetFilePaths() { if (string.IsNullOrEmpty(_callerFilePath)) @@ -21,14 +21,8 @@ public ImmutableArray GetFilePaths() return [.. files]; } - private static string? ThisPath([CallerFilePath] string? callerFilePath = null) + public static string? CallerFilePath([CallerFilePath] string? callerFilePath = null) { return callerFilePath; } - - public static ProjectSourceProvider Get() - { - var thisPath = ThisPath(); - return new(thisPath); - } } diff --git a/Syndiesis/ProjectSourceProviderGetter.cs b/Syndiesis/ProjectSourceProviderGetter.cs new file mode 100644 index 0000000..bf6b8e4 --- /dev/null +++ b/Syndiesis/ProjectSourceProviderGetter.cs @@ -0,0 +1,10 @@ +namespace Syndiesis; + +public static class ProjectSourceProviderGetter +{ + public static ProjectSourceProvider Get() + { + var thisPath = ProjectSourceProvider.CallerFilePath(); + return new(thisPath); + } +}