Skip to content
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

Replace task delays with event listening on tests #1756

Draft
wants to merge 33 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
8a2ac42
Initial refactoring for single event emitter
savpek Mar 30, 2020
595eaf1
Integrated test event emitter as part of test host
savpek Apr 3, 2020
6edc66f
TestEventEmitter as default msbuild sink during testing
savpek Apr 3, 2020
fda1f44
Rename and test fixes
savpek Apr 3, 2020
c579990
Refactored some techical depth from tests
savpek Apr 3, 2020
cdbaa4b
Testfix
savpek Apr 3, 2020
e193a16
Test if one delay is actually not needed
savpek Apr 3, 2020
94cdb40
Testing is test still unstable with *nix
savpek Apr 3, 2020
f064dfd
Yup it definetly still is
savpek Apr 3, 2020
e3e308f
Changed command order
savpek Apr 3, 2020
25e667e
Refactored check for project restored event down to RestoreProject me…
savpek Apr 4, 2020
9a5c9b5
Tweaks for tests and restored temporary commented code
savpek Apr 4, 2020
3cb6b08
Comment update
savpek Apr 5, 2020
e74f0eb
Added warmup of diag service to test host
savpek Apr 5, 2020
a7cf8b8
Added another event wait for initial analysis
savpek Apr 5, 2020
757d07b
Testing if test is now stable in all platforms
savpek Apr 5, 2020
bc71b17
Debugging with timeout on linux/mac is there hint of hang
savpek Apr 6, 2020
10ca305
Testing build stability
savpek Apr 6, 2020
ca4564b
Merge branch 'master' into feature/replace-task-delays-with-event-lis…
savpek Apr 11, 2020
1f56e47
Replaced delay in CsiScriptWithFileCreatedAfterStartingServer with ev…
savpek Apr 13, 2020
336c7e9
Merge branch 'feature/replace-task-delays-with-event-listening' of ht…
savpek Apr 13, 2020
2325ddd
Build stability test
savpek Apr 13, 2020
fffee6d
Build stability test
savpek Apr 13, 2020
3a2a06a
Updated package paths in e2e tests
savpek Apr 13, 2020
374da51
Build stability test
savpek Apr 13, 2020
d1a6e16
Merge branch 'master' into feature/replace-task-delays-with-event-lis…
savpek Apr 15, 2020
f17c6dd
Merge remote-tracking branch 'upstream/master' into feature/replace-t…
savpek Jun 5, 2020
ae4f499
Mergefixes
savpek Jun 5, 2020
7e4aa27
Event based wait for at buffer manager tests
savpek Jun 5, 2020
adeb300
Small cleanup
savpek Jun 6, 2020
1f05362
Yup still unstable
savpek Jun 6, 2020
488bc05
Merge branch 'master' into feature/replace-task-delays-with-event-lis…
savpek Jun 6, 2020
125b429
Merge branch 'master' into feature/replace-task-delays-with-event-lis…
savpek Jun 9, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 0 additions & 4 deletions src/OmniSharp.MSBuild/ProjectManager.cs
Expand Up @@ -10,21 +10,17 @@
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json.Linq;
using OmniSharp.Eventing;
using OmniSharp.FileWatching;
using OmniSharp.Models.UpdateBuffer;
using OmniSharp.MSBuild.Logging;
using OmniSharp.MSBuild.Models.Events;
using OmniSharp.MSBuild.Notification;
using OmniSharp.MSBuild.ProjectFile;
using OmniSharp.Roslyn.CSharp.Services.Diagnostics;
using OmniSharp.Roslyn.CSharp.Services.Refactoring.V2;
using OmniSharp.Options;
using OmniSharp.Roslyn.Utilities;
using OmniSharp.Services;
using OmniSharp.Utilities;
using System.Reflection;
using Microsoft.CodeAnalysis.Diagnostics;
using OmniSharp.Roslyn.EditorConfig;

Expand Down
Expand Up @@ -9,7 +9,6 @@
using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Options;
using Microsoft.Extensions.Logging;
using OmniSharp.Helpers;
using OmniSharp.Models.Diagnostics;
Expand Down
Expand Up @@ -5,7 +5,7 @@
<TargetFramework>netcoreapp2.1</TargetFramework>
<LangVersion>7.1</LangVersion>
<CodeAnalysisRuleSet>default.ruleset</CodeAnalysisRuleSet>
<RestorePackagesPath>./nugets/</RestorePackagesPath>
<RestorePackagesPath>nugets</RestorePackagesPath>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="StyleCop.Analyzers" Version="1.0.2" />
Expand Down
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
<RestorePackagesPath>./nugets/</RestorePackagesPath>
<RestorePackagesPath>nugets</RestorePackagesPath>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.9.8" />
Expand Down
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
<RestorePackagesPath>./nugets/</RestorePackagesPath>
<RestorePackagesPath>nugets</RestorePackagesPath>
<RunAnalyzers>false</RunAnalyzers>
</PropertyGroup>
<ItemGroup>
Expand Down
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
<RestorePackagesPath>./nugets/</RestorePackagesPath>
<RestorePackagesPath>nugets/</RestorePackagesPath>
<RunAnalyzersDuringLiveAnalysis>false</RunAnalyzersDuringLiveAnalysis>
</PropertyGroup>
<ItemGroup>
Expand Down
70 changes: 31 additions & 39 deletions tests/OmniSharp.MSBuild.Tests/ProjectLoadListenerTests.cs
Expand Up @@ -3,14 +3,10 @@
using Microsoft.CodeAnalysis;
using Microsoft.Extensions.Logging;
using OmniSharp.Mef;
using OmniSharp.Models;
using OmniSharp.Models.Events;
using OmniSharp.MSBuild.Notification;
using OmniSharp.Services;
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Composition.Hosting.Core;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
Expand Down Expand Up @@ -96,75 +92,72 @@ public async Task The_target_framework_is_emitted()
{
// Arrange
var expectedTFM = "netcoreapp2.1";
var emitter = new ProjectLoadTestEventEmitter();

using (var testProject = await TestAssets.Instance.GetTestProjectAsync("HelloWorld"))
using (var host = CreateMSBuildTestHost(testProject.Directory, emitter.AsExportDescriptionProvider(LoggerFactory)))
using (var host = CreateMSBuildTestHost(testProject.Directory))
{
Assert.Single(emitter.ReceivedMessages);
Assert.Equal(emitter.ReceivedMessages[0].TargetFrameworks.First(), expectedTFM);
var emitter = host.GetTestEventEmitter();
await emitter.WaitForMessage<ProjectConfigurationMessage>();
Assert.Equal(emitter.Messages.OfType<ProjectConfigurationMessage>().First().TargetFrameworks.First(), expectedTFM);
}
}

[Fact]
public async Task If_there_is_a_solution_file_the_project_guid_present_in_it_is_emitted()
{
// Arrange
var emitter = new ProjectLoadTestEventEmitter();

using (var testProject = await TestAssets.Instance.GetTestProjectAsync("ProjectAndSolution"))
using (var host = CreateMSBuildTestHost(testProject.Directory, emitter.AsExportDescriptionProvider(LoggerFactory)))
using (var host = CreateMSBuildTestHost(testProject.Directory))
{
var emitter = host.GetTestEventEmitter();
var expectedGuid = "A4C2694D-AEB4-4CB1-8951-5290424EF883".ToLower();
Assert.Single(emitter.ReceivedMessages);
Assert.Equal(emitter.ReceivedMessages[0].ProjectId, expectedGuid);
await emitter.WaitForMessage<ProjectConfigurationMessage>();
Assert.Equal(emitter.Messages.OfType<ProjectConfigurationMessage>().First().ProjectId, expectedGuid);
}
}

[Fact]
public async Task If_there_is_no_solution_file_the_hash_of_project_file_content_and_name_is_emitted()
{
// Arrange
var emitter = new ProjectLoadTestEventEmitter();

using (var testProject = await TestAssets.Instance.GetTestProjectAsync("HelloWorld"))
using (var host = CreateMSBuildTestHost(testProject.Directory, emitter.AsExportDescriptionProvider(LoggerFactory)))
using (var host = CreateMSBuildTestHost(testProject.Directory))
{
var emitter = host.GetTestEventEmitter();
var projectFileContent = File.ReadAllText(Directory.GetFiles(testProject.Directory, "*.csproj").Single());
var expectedGuid = GetHashedReference($"Filename: HelloWorld.csproj\n{projectFileContent}");
Assert.Single(emitter.ReceivedMessages);
Assert.Equal(emitter.ReceivedMessages[0].ProjectId, expectedGuid);
await emitter.WaitForMessage<ProjectConfigurationMessage>();
Assert.Equal(emitter.Messages.OfType<ProjectConfigurationMessage>().First().ProjectId, expectedGuid);
}
}

[Fact]
public async Task Given_a_restored_project_the_references_are_emitted()
{
var emitter = new ProjectLoadTestEventEmitter();
// TODO: ProjectConfigurationMessage doesn't get emitted after host startup on restore with references, for this reason restore is done
// before host startup to support custom event listning
var testEventEmitter = new TestEventEmitter();
var descriptor = MefValueProvider.From<IMSBuildEventSink>(new ProjectLoadListener(new LoggerFactory(), testEventEmitter));

using (var testProject = await TestAssets.Instance.GetTestProjectAsync("HelloWorld"))
{
var dotnetCliService = new DotNetCliService(LoggerFactory, emitter);
await dotnetCliService.RestoreAsync(testProject.Directory);
using (var host = CreateMSBuildTestHost(testProject.Directory, emitter.AsExportDescriptionProvider(LoggerFactory)))
await new DotNetCliService(new LoggerFactory(), testEventEmitter).RestoreAsync(testProject.Directory);
using (var host = CreateMSBuildTestHost(testProject.Directory, additionalExports: new[] { descriptor }))
{
Assert.Single(emitter.ReceivedMessages);
Assert.NotEmpty(emitter.ReceivedMessages[0].References.Where(reference => reference == GetHashedReference("system.core")));
await testEventEmitter.WaitForMessage<ProjectConfigurationMessage>();
Assert.NotEmpty(testEventEmitter.Messages.OfType<ProjectConfigurationMessage>().Last().References.Where(reference => reference == GetHashedReference("system.core")));
}
}
}


[Fact]
public async Task If_there_are_multiple_target_frameworks_they_are_emitted()
{
var emitter = new ProjectLoadTestEventEmitter();

using (var testProject = await TestAssets.Instance.GetTestProjectAsync("ProjectWithMultiTFMLib/Lib"))
using (var host = CreateMSBuildTestHost(testProject.Directory, emitter.AsExportDescriptionProvider(LoggerFactory)))
using (var host = CreateMSBuildTestHost(testProject.Directory))
{
Assert.Single(emitter.ReceivedMessages);
var tfm = emitter.ReceivedMessages[0].TargetFrameworks.ToArray();
var emitter = host.GetTestEventEmitter();
Assert.NotEmpty(emitter.Messages.OfType<ProjectConfigurationMessage>());

var tfm = emitter.Messages.OfType<ProjectConfigurationMessage>().Last().TargetFrameworks.ToArray();
Assert.Equal(2, tfm.Count());
Assert.Equal("netstandard1.3", tfm[0]);
Assert.Equal("netstandard2.0", tfm[1]);
Expand All @@ -174,15 +167,14 @@ public async Task If_there_are_multiple_target_frameworks_they_are_emitted()
[Fact]
public async Task The_hashed_references_of_the_source_files_are_emitted()
{
// Arrange
var emitter = new ProjectLoadTestEventEmitter();

using (var testProject = await TestAssets.Instance.GetTestProjectAsync("HelloWorld"))
using (var host = CreateMSBuildTestHost(testProject.Directory, emitter.AsExportDescriptionProvider(LoggerFactory)))
using (var host = CreateMSBuildTestHost(testProject.Directory))
{
Assert.Single(emitter.ReceivedMessages);
Assert.Single(emitter.ReceivedMessages[0].FileExtensions);
Assert.Equal(emitter.ReceivedMessages[0].FileExtensions.First(), GetHashedFileExtension(".cs"));
var emitter = host.GetTestEventEmitter();

await emitter.WaitForMessage<ProjectConfigurationMessage>();
Assert.Single(emitter.Messages.OfType<ProjectConfigurationMessage>().First().FileExtensions);
Assert.Equal(emitter.Messages.OfType<ProjectConfigurationMessage>().First().FileExtensions.First(), GetHashedFileExtension(".cs"));
}
}

Expand Down
47 changes: 0 additions & 47 deletions tests/OmniSharp.MSBuild.Tests/ProjectLoadTestEventEmitter.cs

This file was deleted.