Skip to content

Commit

Permalink
Include the large source test
Browse files Browse the repository at this point in the history
  • Loading branch information
Rekkonnect committed Aug 10, 2024
1 parent 94eaff5 commit f0993d8
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 41 deletions.
16 changes: 14 additions & 2 deletions Syndiesis.Tests/BaseProjectCodeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<FileInfo> FilesToTest
protected static readonly ProjectSourceProvider TestSourceProvider
= Syndiesis.Tests.ProjectSourceProviderGetter.Get();

protected static readonly ImmutableArray<FileInfo> MainFilesToTest
= SourceProvider.GetFilePaths();

protected static readonly ImmutableArray<FileInfo> TestFilesToTest
= TestSourceProvider.GetFilePaths();

protected static readonly ImmutableArray<FileInfo> FilesToTest =
[
.. MainFilesToTest,
.. TestFilesToTest,
];

[Test]
public async Task TestAllFilesIndependently()
{
Expand Down
56 changes: 27 additions & 29 deletions Syndiesis.Tests/NodeViewDetailsHandlerTests.cs
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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)
{
Expand Down Expand Up @@ -55,6 +70,7 @@ private static async Task TestNode(
{
Assert.That(rootNode?.FullSpan, Is.EqualTo(node.FullSpan));
}

}

private static async Task<NodeViewAnalysisExecution> TestExecutingResult(
Expand All @@ -68,26 +84,8 @@ private static async Task<NodeViewAnalysisExecution> 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}");
}
}
}
10 changes: 10 additions & 0 deletions Syndiesis.Tests/ProjectSourceProviderGetter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace Syndiesis.Tests;

public static class ProjectSourceProviderGetter
{
public static ProjectSourceProvider Get()
{
var thisPath = ProjectSourceProvider.CallerFilePath();
return new(thisPath);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Garyon.Functions;
using Syndiesis.Core.DisplayAnalysis;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
Expand Down Expand Up @@ -40,14 +41,16 @@ SemanticModelSection SemanticModel
];
}

public async Task<bool> AwaitAllLoaded()
public async Task<bool> AwaitAllLoaded(TimeSpan expectedDelay = default)
{
var nodeLoaders = AllNodes()
.Select(s => s.NodeLoader)
.Where(Predicates.NotNull)
.ToList()
;

await Task.Delay(expectedDelay);

await Task.WhenAll(nodeLoaders!);
return nodeLoaders.All(l => l!.IsCompletedSuccessfully);
}
Expand Down
12 changes: 3 additions & 9 deletions Syndiesis/ProjectSourceProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

namespace Syndiesis;

public sealed class ProjectSourceProvider(string? callerFilePath)
public class ProjectSourceProvider(string? callerFilePath)
{
private readonly string? _callerFilePath = callerFilePath;

public ImmutableArray<FileInfo> GetFilePaths()
{
if (string.IsNullOrEmpty(_callerFilePath))
Expand All @@ -21,14 +21,8 @@ public ImmutableArray<FileInfo> 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);
}
}
10 changes: 10 additions & 0 deletions Syndiesis/ProjectSourceProviderGetter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace Syndiesis;

public static class ProjectSourceProviderGetter
{
public static ProjectSourceProvider Get()
{
var thisPath = ProjectSourceProvider.CallerFilePath();
return new(thisPath);
}
}

0 comments on commit f0993d8

Please sign in to comment.