-
Notifications
You must be signed in to change notification settings - Fork 563
Integration test #317
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
Integration test #317
Changes from all commits
9b014c5
35ed865
9d8ca53
6234294
2f1c8c9
e405038
534d012
ad11f21
8f9bf22
f067391
36aa0e2
8d618b7
fb85085
31a2dda
959161c
f48a9f7
3578c81
1e0dcbb
8eb51bc
c0998c6
7c9fd73
e81fde8
683185d
8c99a67
2372d4f
ca75f01
98c3dd7
eef5590
cd0d831
8a194b3
1dc938b
b122d7f
3675287
0de4baf
7fd07ff
8f8cade
efed370
0c84608
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Diagnostics; | ||
| using System.IO; | ||
| using System.Linq; | ||
| using System.Net.Http; | ||
| using System.Runtime.CompilerServices; | ||
| using System.Text; | ||
| using System.Threading.Tasks; | ||
| using MLS.Agent; | ||
| using MLS.Agent.Tools; | ||
| using WorkspaceServer; | ||
|
|
||
| namespace NotIntegrationTests | ||
| { | ||
| public class DotnetTryFixture : IDisposable | ||
| { | ||
| private DisposableDirectory _disposableDirectory; | ||
| private Process _process; | ||
| private HttpClient _client; | ||
| private AsyncLazy<bool> _lazyReady; | ||
|
|
||
| public DotnetTryFixture() | ||
| { | ||
| _disposableDirectory = DisposableDirectory.Create(); | ||
| _lazyReady = new AsyncLazy<bool>(ReadyAsync); | ||
| } | ||
|
|
||
| public void Dispose() | ||
| { | ||
| _process?.Kill(); | ||
| _disposableDirectory.Dispose(); | ||
| } | ||
|
|
||
| private async Task<bool> ReadyAsync() | ||
| { | ||
| var dotnet = new Dotnet(); | ||
| var installResult = await dotnet.ToolInstall("dotnet-try", _disposableDirectory.Directory, version: "1.0.44142.42", addSource: GetPackageSource()); | ||
| installResult.ThrowOnFailure(); | ||
|
|
||
| await Start(); | ||
| return true; | ||
| } | ||
|
|
||
| private async Task Start() | ||
| { | ||
| var tcs = new TaskCompletionSource<bool>(); | ||
| var dotnetTry = _disposableDirectory.Directory.GetFiles("dotnet-try*").First().FullName; | ||
| _process = CommandLine.StartProcess(dotnetTry, "--port 7891 hosted", _disposableDirectory.Directory, | ||
| output => | ||
| { | ||
| if (output.Contains("Now listening on")) | ||
| { | ||
| tcs.SetResult(true); | ||
| } | ||
| }, | ||
| error => | ||
| { | ||
| if (!string.IsNullOrWhiteSpace(error)) | ||
| { | ||
| tcs.TrySetException(new Exception(error)); | ||
| Console.Write(error); | ||
| } | ||
| }); | ||
|
|
||
| _client = new HttpClient(); | ||
| _client.BaseAddress = new Uri("http://localhost:7891"); | ||
| await tcs.Task; | ||
| } | ||
|
|
||
| private PackageSource GetPackageSource([CallerFilePath] string callerFile = "") | ||
| { | ||
| var dotnetTryPackageSource = Environment.GetEnvironmentVariable("PACKAGESOURCE"); | ||
|
|
||
| var directory = !string.IsNullOrWhiteSpace(dotnetTryPackageSource) | ||
| ? new DirectoryInfo(dotnetTryPackageSource) | ||
| : new DirectoryInfo(Path.Combine(Path.GetDirectoryName(callerFile), "../artifacts/packages/Debug/Shipping")); | ||
|
|
||
| if (!directory.Exists) | ||
| { | ||
| throw new Exception($"Expected packages directory {directory.FullName} to exist but it does not"); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a more specific exception that would be appropriate here? |
||
| } | ||
|
|
||
| return new PackageSource(directory.FullName); | ||
| } | ||
|
|
||
| public async Task<HttpResponseMessage> GetAsync(string requestUri) | ||
| { | ||
| await _lazyReady.ValueAsync(); | ||
| return await _client.GetAsync(requestUri); | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| using System; | ||
| using System.Threading.Tasks; | ||
| using FluentAssertions; | ||
| using Xunit; | ||
|
|
||
| namespace NotIntegrationTests | ||
| { | ||
| public class UnitTest1 : IClassFixture<DotnetTryFixture> | ||
| { | ||
| private readonly DotnetTryFixture _fixture; | ||
|
|
||
| public UnitTest1(DotnetTryFixture fixture) | ||
| { | ||
| _fixture = fixture; | ||
| } | ||
|
|
||
| [Fact(Skip = "This doesn't work yet")] | ||
| public async Task Can_serve_blazor_console_code_runner() | ||
| { | ||
| var response = await _fixture.GetAsync(@"/LocalCodeRunner/blazor-console"); | ||
|
|
||
| response.StatusCode.Should().Be(200); | ||
| var result = await response.Content.ReadAsStringAsync(); | ||
| result.Should().Contain("Loading..."); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task Can_serve_bundleCss() | ||
| { | ||
| var response = await _fixture.GetAsync(@"/client/bundle.css"); | ||
| response.StatusCode.Should().Be(200); | ||
| var content = await response.Content.ReadAsStringAsync(); | ||
| content.Should().NotBeNullOrEmpty(); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task Can_serve_bundlejs() | ||
| { | ||
| var response = await _fixture.GetAsync(@"/client/2.bundle.js"); | ||
| response.StatusCode.Should().Be(200); | ||
| var content = await response.Content.ReadAsStringAsync(); | ||
| content.Should().NotBeNullOrEmpty(); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task Can_serve_clientapi() | ||
| { | ||
| var response = await _fixture.GetAsync(@"/api/trydotnet.min.js"); | ||
| response.StatusCode.Should().Be(200); | ||
| var content = await response.Content.ReadAsStringAsync(); | ||
| content.Should().NotBeNullOrEmpty(); | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFramework>netcoreapp3.0</TargetFramework> | ||
|
|
||
| <IsPackable>true</IsPackable> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="Clockwise" Version="1.0.261-beta" /> | ||
| <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.0.1" /> | ||
| <PackageReference Include="xunit" Version="2.4.0" /> | ||
| <PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" /> | ||
| <PackageReference Include="FluentAssertions" Version="5.7.0" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\MLS.Agent.Tools\MLS.Agent.Tools.csproj" /> | ||
| <ProjectReference Include="..\MLS.Agent\MLS.Agent.csproj" /> | ||
| <ProjectReference Include="..\WorkspaceServer\WorkspaceServer.csproj" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -108,13 +108,19 @@ jobs: | |
| continueOnError: true | ||
| condition: always() | ||
|
|
||
| - ${{ if and(ne(variables['System.TeamProject'], 'public'), notin(variables['Build.Reason'], 'PullRequest')) }}: | ||
| - task: PublishBuildArtifacts@1 | ||
| displayName: Publish packages to artifacts container | ||
| inputs: | ||
| pathToPublish: $(Build.SourcesDirectory)\artifacts\packages\$(_BuildConfig) | ||
| artifactName: packages | ||
| artifactType: container | ||
| - task: PublishBuildArtifacts@1 | ||
| displayName: Publish packages to artifacts container | ||
| inputs: | ||
| pathToPublish: $(Build.SourcesDirectory)\artifacts\packages\$(_BuildConfig) | ||
| artifactName: packages | ||
| artifactType: container | ||
|
|
||
| - task: PublishBuildArtifacts@1 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If publishing the tests like this you can remove |
||
| displayName: Publish integration tests dll | ||
| inputs: | ||
| pathToPublish: $(Build.SourcesDirectory)\artifacts\bin\NotIntegrationTests\$(_BuildConfig) | ||
| artifactName: integrationTests | ||
| artifactType: container | ||
|
|
||
| - template: /eng/common/templates/jobs/jobs.yml | ||
| parameters: | ||
|
|
@@ -126,6 +132,52 @@ jobs: | |
| enableTelemetry: true | ||
| helixRepo: dotnet/try | ||
| jobs: | ||
| - job: IntegrationTest | ||
| dependsOn: Windows_NT | ||
| condition: succeeded() | ||
| pool: | ||
| vmImage: ubuntu-16.04 | ||
| variables: | ||
| - name: PACKAGESOURCE | ||
| value: $(System.DefaultWorkingDirectory)/packages/Shipping | ||
| - name: TryDotNetPackagesPath | ||
| value: $(Build.SourcesDirectory)/.trydotnet/packages | ||
| steps: | ||
| - checkout: none #skip checking out the default repository resource | ||
| - task: UseDotNet@2 | ||
| displayName: Add dotnet | ||
| inputs: | ||
| packageType: sdk | ||
| version: $(DotNetSdkVersion) | ||
| installationPath: $(Agent.ToolsDirectory)/dotnet | ||
|
|
||
| - script: dotnet new -i Microsoft.AspNetCore.Blazor.Templates::$(BlazorTemplateVersion) | ||
| displayName: Install Blazor templates | ||
|
|
||
| - task: DownloadBuildArtifacts@0 | ||
| displayName: 'Download built packages' | ||
| inputs: | ||
| artifactName: packages | ||
| downloadPath: $(System.DefaultWorkingDirectory) | ||
|
|
||
| - task: DownloadBuildArtifacts@0 | ||
| displayName: 'Download built integrationtests' | ||
| inputs: | ||
| artifactName: integrationTests | ||
| downloadPath: $(System.DefaultWorkingDirectory) | ||
|
|
||
| - script: dotnet vstest $(System.DefaultWorkingDirectory)/integrationTests/netcoreapp3.0/NotIntegrationTests.dll --ResultsDirectory:$(System.DefaultWorkingDirectory)/testResults | tee $(Build.SourcesDirectory)\artifacts\log\$(_BuildConfig)\log.txt | ||
| displayName: Run integration tests | ||
|
|
||
| - task: PublishTestResults@2 | ||
| displayName: Publish NPM Test Results | ||
| inputs: | ||
| testResultsFormat: 'VSTest' | ||
| testResultsFiles: '*.trx' | ||
| searchFolder: '$(SystemWorkingDirectory)/testResults' | ||
| continueOnError: true | ||
| condition: always() | ||
|
|
||
| - job: Linux | ||
| pool: | ||
| vmImage: ubuntu-16.04 | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well what are they then?