Skip to content

Commit

Permalink
Cleanups and resilence fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobbe Gyllebring committed Aug 2, 2018
1 parent e4ada0d commit 32ee992
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 46 deletions.
2 changes: 1 addition & 1 deletion Source/Cone.TestAdapter/Cone.TestAdapter.csproj
Expand Up @@ -8,10 +8,10 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.TestPlatform.ObjectModel" Version="15.7.2" PrivateAssets="All" />
<ProjectReference Include="..\Cone\Cone.csproj" PrivateAssets="All" />
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
</ItemGroup>
<ItemGroup>
<Reference Include="System" />
<ProjectReference Include="..\Cone\Cone.csproj" PrivateAssets="All" />
</ItemGroup>
</Project>
70 changes: 46 additions & 24 deletions Source/Cone.TestAdapter/ConeTestAdapterProxy.cs
Expand Up @@ -16,7 +16,8 @@ class ConeTestAdapterProxy : MarshalByRefObject

public int DiscoverTests(string source, ICrossDomainLogger sink) {
var session = CreateSession(sink, "DiscoverTests", source);
session.GetTestExecutor = _ => new DryRunTestExecutor();
var dryRun = new DryRunTestExecutor();
session.GetTestExecutor = _ => dryRun;

return RunSession(source, true, sink, session);
}
Expand Down Expand Up @@ -63,33 +64,58 @@ class DebugTapLogger : ISessionLogger
{
class DebugTapSuiteLogger : ISuiteLogger
{
public ITestLogger BeginTest(IConeTest test) {
return new DebugTapTestLogger();
readonly DebugTapLogger parent;
readonly IConeSuite suite;
public DebugTapSuiteLogger(DebugTapLogger parent, IConeSuite suite) {
this.parent = parent;
this.suite = suite;
}

public void EndSuite() {
public ITestLogger BeginTest(IConeTest test) {
Write(new { beginTest = new {
parent.pid,
suiteName = suite.Name,
testName = test.TestName.Name,
} });
return new DebugTapTestLogger(parent, test);
}

public void EndSuite() =>
Write(new { endSuite = new { parent.pid, name = suite.Name } });

void Write(object obj) => parent.Write(obj);
}

class DebugTapTestLogger : ITestLogger
{
public void Failure(ConeTestFailure failure) {
}
readonly DebugTapLogger parent;
readonly IConeTest test;

public void Pending(string reason) {
public DebugTapTestLogger(DebugTapLogger parent, IConeTest test) {
this.parent = parent;
this.test = test;
}

public void Skipped() {
}
public void Failure(ConeTestFailure failure) => TestResult("fail", failure.ToString());

public void Success() {
}
public void Pending(string reason) => TestResult("pending", reason);

public void TestFinished() {
}
public void Skipped() => TestResult("skipped", string.Empty);

public void TestStarted() {
}
public void Success() => TestResult("success", string.Empty);

public void TestFinished() { }

public void TestStarted() { }

void TestResult(string outcome, string message) =>
parent.Write(new { testResult = new {
parent.pid,
suiteName = test.Suite.Name,
testName = test.TestName.Name,
outcome,
message,
} });
}

readonly Stream output;
Expand All @@ -105,22 +131,18 @@ class DebugTapTestLogger : ITestLogger
this.source = source;
}

public static DebugTapLogger Create(Stream output, string context, string source) {
return new DebugTapLogger(output, Process.GetCurrentProcess().Id, context, source);
}
public static DebugTapLogger Create(Stream output, string context, string source)=>
new DebugTapLogger(output, Process.GetCurrentProcess().Id, context, source);

public void BeginSession() {
Write(new { beginSession = new { pid, context, source }});
}
public void BeginSession() => Write(new { beginSession = new { pid, context, source }});

public ISuiteLogger BeginSuite(IConeSuite suite) {
Write(new { beginSuite = new { pid, name = suite.Name } });
return new DebugTapSuiteLogger();
return new DebugTapSuiteLogger(this, suite);
}

public void EndSession() {
public void EndSession() =>
Write(new { endSession = new { pid } });
}

public void WriteInfo(Action<ISessionWriter> output) {
}
Expand Down
10 changes: 8 additions & 2 deletions Source/Cone.TestAdapter/ConeTestDiscoverer.cs
Expand Up @@ -2,21 +2,27 @@
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;
using System;
using System.Collections.Generic;
using System.Diagnostics;

namespace Cone.TestAdapter
{
[ExtensionUri(ConeTestExecutor.ExecutorUriString), FileExtension(".dll"), DefaultExecutorUri(ConeTestExecutor.ExecutorUriString)]
[DefaultExecutorUri(ConeTestExecutor.ExecutorUriString)]
[FileExtension(".dll")]
public class ConeTestDiscoverer : ITestDiscoverer
{
public void DiscoverTests(IEnumerable<string> sources, IDiscoveryContext discoveryContext, IMessageLogger logger, ITestCaseDiscoverySink discoverySink) {
foreach(var source in sources) {
foreach (var source in sources)
try {
logger.SendMessage(TestMessageLevel.Informational, $"Checking {source}");
var xDomainSink = new TestAdapterLogger(logger, source);
xDomainSink.OnBeginTest += (_, e) => discoverySink.SendTestCase(e.TestCase);
CrossDomainConeRunner.WithProxyInDomain<ConeTestAdapterProxy, int>(string.Empty,
new [] { source, },
proxy => proxy.DiscoverTests(source, xDomainSink));
} catch(Exception ex) {
logger.SendMessage(TestMessageLevel.Error, "Failed to discover tests in " + source + "\n" + ex);
}
}
}
Expand Down
36 changes: 21 additions & 15 deletions Source/Cone.TestAdapter/ConeTestExecutor.cs
@@ -1,10 +1,10 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using Cone.Runners;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;

namespace Cone.TestAdapter
{
Expand All @@ -24,27 +24,33 @@ public class ConeTestExecutor : ITestExecutor
RunSourceInDomain(source, runContext, frameworkHandle);
}

void RunSourceInDomain(string source, IRunContext runContext, IFrameworkHandle frameworkHandle) {
void RunSourceInDomain(string source, IRunContext runContext, IFrameworkHandle frameworkHandle) {
frameworkHandle.SendMessage(TestMessageLevel.Informational, "Running Source: " + source);
var xDomainSink = CreateLogger(frameworkHandle, source);
CrossDomainConeRunner.WithProxyInDomain<ConeTestAdapterProxy, int>(string.Empty, new [] { source },
proxy => proxy.RunTests(source, xDomainSink));
}

TestAdapterLogger CreateLogger(IFrameworkHandle frameworkHandle, string source) {
var xDomainSink = new TestAdapterLogger(frameworkHandle, source);
xDomainSink.OnSuccess += (_, e) => frameworkHandle.RecordResult(new TestResult(e.TestCase) { Outcome = TestOutcome.Passed, Duration = e.Duration, });
xDomainSink.OnPending += (_, e) => frameworkHandle.RecordResult(new TestResult(e.TestCase) { Outcome = TestOutcome.Skipped, Duration = e.Duration });
xDomainSink.OnFailure += (_, e) => {
frameworkHandle.RecordResult(new TestResult(e.TestCase) {
Outcome = TestOutcome.Failed,
Duration = e.Duration,
ErrorMessage = e.ErrorMessage,
ErrorStackTrace = e.ErrorStackTrace,
});
};
TestAdapterLogger CreateLogger(IFrameworkHandle frameworkHandle, string source) {
var xDomainSink = new TestAdapterLogger(frameworkHandle, source);
xDomainSink.OnBeginTest += (_, e) => frameworkHandle.RecordStart(e.TestCase);
xDomainSink.OnSuccess += (_, e) => frameworkHandle.RecordResult(new TestResult(e.TestCase) {
Outcome = TestOutcome.Passed,
Duration = e.Duration,
});
xDomainSink.OnPending += (_, e) => frameworkHandle.RecordResult(new TestResult(e.TestCase) {
Outcome = TestOutcome.Skipped,
Duration = e.Duration
});
xDomainSink.OnFailure += (_, e) => frameworkHandle.RecordResult(new TestResult(e.TestCase) {
Outcome = TestOutcome.Failed,
Duration = e.Duration,
ErrorMessage = e.ErrorMessage,
ErrorStackTrace = e.ErrorStackTrace,
});
return xDomainSink;
}

public void Cancel() { }
}
}
3 changes: 1 addition & 2 deletions Source/Cone.TestAdapter/TestAdapterLogger.cs
Expand Up @@ -72,9 +72,8 @@ class TestAdapterLogger : MarshalByRefObject, ICrossDomainLogger
DisplayName = testCase.Name,
};
newTestCase.Traits.Add("Context", testCase.Context);
OnBeginTest?.Invoke(this, new TestAdapterEventArgs { TestCase = newTestCase });

testCases.TryAdd(testCase, new KeyValuePair<TestCase, Stopwatch>(newTestCase, Stopwatch.StartNew()));
OnBeginTest?.Invoke(this, new TestAdapterEventArgs { TestCase = newTestCase });
}
}
}
4 changes: 2 additions & 2 deletions Source/Version.cs
Expand Up @@ -2,5 +2,5 @@
using System.Runtime.InteropServices;

[assembly: ComVisible(false)]
[assembly: AssemblyVersion("2018.07.31")]
[assembly: AssemblyInformationalVersion("2018.07.31")]
[assembly: AssemblyVersion("2018.07.32")]
[assembly: AssemblyInformationalVersion("2018.07.32")]

0 comments on commit 32ee992

Please sign in to comment.