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

Use fakes to surround vstest core and test it #3347

Merged
merged 37 commits into from
Feb 21, 2022
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
cf19aa2
use fakes over mocks
nohwnd Feb 7, 2022
8df3854
Isolating
nohwnd Feb 7, 2022
308ccd2
More code
nohwnd Feb 7, 2022
69ee04e
Add response pairs
nohwnd Feb 7, 2022
eb37be0
respond me
nohwnd Feb 8, 2022
1a8090c
Add comment
nohwnd Feb 8, 2022
6053c81
stuff
nohwnd Feb 9, 2022
6766ce6
Chased down the teardown bug.
nohwnd Feb 9, 2022
148086a
Passing test finally, now refactor
nohwnd Feb 10, 2022
e3ec7b1
Merge branch 'main' into fakes-over-mocks
nohwnd Feb 10, 2022
ae16fa7
Merge branch 'main' into fakes-over-mocks
nohwnd Feb 16, 2022
9ce6bc0
Format the test names so I can read them better
nohwnd Feb 16, 2022
d6be5d5
About to split up to multiple assemblies.
nohwnd Feb 16, 2022
8c91ed7
make code succint
nohwnd Feb 16, 2022
aae9dcd
more cleanup
nohwnd Feb 16, 2022
d4aad3a
Merge branch 'main' into fakes-over-mocks
nohwnd Feb 17, 2022
1199580
More cleanup
nohwnd Feb 17, 2022
4cd58c7
use the correct testhost actually.
nohwnd Feb 17, 2022
a638603
Test multi tfm
nohwnd Feb 17, 2022
2f8f0d6
Add test for the current behavior of tfms
nohwnd Feb 18, 2022
48d6a0b
Check warning.
nohwnd Feb 18, 2022
1c3ca5c
Allow 0 tests to be returned.
nohwnd Feb 18, 2022
1ea876b
Add comment
nohwnd Feb 18, 2022
b3d128d
Apply suggestions from code review
nohwnd Feb 18, 2022
ab696c9
Revert playground
nohwnd Feb 18, 2022
183b711
Fix protected changes
nohwnd Feb 18, 2022
346fe30
Remove using
nohwnd Feb 18, 2022
a3635da
More cosmetic issues
nohwnd Feb 18, 2022
3c31acf
Fix build issues
nohwnd Feb 18, 2022
7522f78
Merge branch 'main' into fakes-over-mocks
nohwnd Feb 18, 2022
5b12b0c
Apply suggestions from code review
nohwnd Feb 21, 2022
da61447
Apply suggestions from code review
nohwnd Feb 21, 2022
35c8809
Update test/Intent/Extensions.cs
nohwnd Feb 21, 2022
3f29dea
Fix review comments
nohwnd Feb 21, 2022
6b0f22a
Merge branch 'fakes-over-mocks' of https://github.com/nohwnd/vstest i…
nohwnd Feb 21, 2022
1ec47bf
Remove empty line
nohwnd Feb 21, 2022
30752dc
Fix errors in release
nohwnd Feb 21, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions TestPlatform.sln
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MSTest1", "playground\MSTes
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AttachmentProcessorDataCollector", "test\TestAssets\AttachmentProcessorDataCollector\AttachmentProcessorDataCollector.csproj", "{B6AF6BCD-64C6-4F4E-ABCA-C8AA2AA66B7B}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "vstest.ProgrammerTests", "test\vstest.ProgrammerTests\vstest.ProgrammerTests.csproj", "{B1F84FD8-6150-4ECA-9AD7-C316E04E17D8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Intent", "test\Intent\Intent.csproj", "{BFBB35C9-6437-480A-8DCC-AE3700110E7D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Intent.Primitives", "test\Intent.Primitives\Intent.Primitives.csproj", "{29270853-90DC-4C39-9621-F47AE40A79B6}"
EndProject
Global
GlobalSection(SharedMSBuildProjectFiles) = preSolution
src\Microsoft.TestPlatform.Execution.Shared\Microsoft.TestPlatform.Execution.Shared.projitems*{10b6ade1-f808-4612-801d-4452f5b52242}*SharedItemsImports = 5
Expand Down Expand Up @@ -880,6 +886,42 @@ Global
{B6AF6BCD-64C6-4F4E-ABCA-C8AA2AA66B7B}.Release|x64.Build.0 = Release|Any CPU
{B6AF6BCD-64C6-4F4E-ABCA-C8AA2AA66B7B}.Release|x86.ActiveCfg = Release|Any CPU
{B6AF6BCD-64C6-4F4E-ABCA-C8AA2AA66B7B}.Release|x86.Build.0 = Release|Any CPU
{B1F84FD8-6150-4ECA-9AD7-C316E04E17D8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B1F84FD8-6150-4ECA-9AD7-C316E04E17D8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B1F84FD8-6150-4ECA-9AD7-C316E04E17D8}.Debug|x64.ActiveCfg = Debug|Any CPU
{B1F84FD8-6150-4ECA-9AD7-C316E04E17D8}.Debug|x64.Build.0 = Debug|Any CPU
{B1F84FD8-6150-4ECA-9AD7-C316E04E17D8}.Debug|x86.ActiveCfg = Debug|Any CPU
{B1F84FD8-6150-4ECA-9AD7-C316E04E17D8}.Debug|x86.Build.0 = Debug|Any CPU
{B1F84FD8-6150-4ECA-9AD7-C316E04E17D8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B1F84FD8-6150-4ECA-9AD7-C316E04E17D8}.Release|Any CPU.Build.0 = Release|Any CPU
{B1F84FD8-6150-4ECA-9AD7-C316E04E17D8}.Release|x64.ActiveCfg = Release|Any CPU
{B1F84FD8-6150-4ECA-9AD7-C316E04E17D8}.Release|x64.Build.0 = Release|Any CPU
{B1F84FD8-6150-4ECA-9AD7-C316E04E17D8}.Release|x86.ActiveCfg = Release|Any CPU
{B1F84FD8-6150-4ECA-9AD7-C316E04E17D8}.Release|x86.Build.0 = Release|Any CPU
{BFBB35C9-6437-480A-8DCC-AE3700110E7D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BFBB35C9-6437-480A-8DCC-AE3700110E7D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BFBB35C9-6437-480A-8DCC-AE3700110E7D}.Debug|x64.ActiveCfg = Debug|Any CPU
{BFBB35C9-6437-480A-8DCC-AE3700110E7D}.Debug|x64.Build.0 = Debug|Any CPU
{BFBB35C9-6437-480A-8DCC-AE3700110E7D}.Debug|x86.ActiveCfg = Debug|Any CPU
{BFBB35C9-6437-480A-8DCC-AE3700110E7D}.Debug|x86.Build.0 = Debug|Any CPU
{BFBB35C9-6437-480A-8DCC-AE3700110E7D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BFBB35C9-6437-480A-8DCC-AE3700110E7D}.Release|Any CPU.Build.0 = Release|Any CPU
{BFBB35C9-6437-480A-8DCC-AE3700110E7D}.Release|x64.ActiveCfg = Release|Any CPU
{BFBB35C9-6437-480A-8DCC-AE3700110E7D}.Release|x64.Build.0 = Release|Any CPU
{BFBB35C9-6437-480A-8DCC-AE3700110E7D}.Release|x86.ActiveCfg = Release|Any CPU
{BFBB35C9-6437-480A-8DCC-AE3700110E7D}.Release|x86.Build.0 = Release|Any CPU
{29270853-90DC-4C39-9621-F47AE40A79B6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{29270853-90DC-4C39-9621-F47AE40A79B6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{29270853-90DC-4C39-9621-F47AE40A79B6}.Debug|x64.ActiveCfg = Debug|Any CPU
{29270853-90DC-4C39-9621-F47AE40A79B6}.Debug|x64.Build.0 = Debug|Any CPU
{29270853-90DC-4C39-9621-F47AE40A79B6}.Debug|x86.ActiveCfg = Debug|Any CPU
{29270853-90DC-4C39-9621-F47AE40A79B6}.Debug|x86.Build.0 = Debug|Any CPU
{29270853-90DC-4C39-9621-F47AE40A79B6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{29270853-90DC-4C39-9621-F47AE40A79B6}.Release|Any CPU.Build.0 = Release|Any CPU
{29270853-90DC-4C39-9621-F47AE40A79B6}.Release|x64.ActiveCfg = Release|Any CPU
{29270853-90DC-4C39-9621-F47AE40A79B6}.Release|x64.Build.0 = Release|Any CPU
{29270853-90DC-4C39-9621-F47AE40A79B6}.Release|x86.ActiveCfg = Release|Any CPU
{29270853-90DC-4C39-9621-F47AE40A79B6}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -955,6 +997,9 @@ Global
{545A88D3-1AE2-4D39-9B7C-C691768AD17F} = {6CE2F530-582B-4695-A209-41065E103426}
{57A61A09-10AD-44BE-8DF4-A6FD108F7DF7} = {6CE2F530-582B-4695-A209-41065E103426}
{B6AF6BCD-64C6-4F4E-ABCA-C8AA2AA66B7B} = {D9A30E32-D466-4EC5-B4F2-62E17562279B}
{B1F84FD8-6150-4ECA-9AD7-C316E04E17D8} = {B27FAFDF-2DBA-4AB0-BA85-FD5F21D359D6}
{BFBB35C9-6437-480A-8DCC-AE3700110E7D} = {B27FAFDF-2DBA-4AB0-BA85-FD5F21D359D6}
{29270853-90DC-4C39-9621-F47AE40A79B6} = {B27FAFDF-2DBA-4AB0-BA85-FD5F21D359D6}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {0541B30C-FF51-4E28-B172-83F5F3934BCD}
Expand Down
4 changes: 4 additions & 0 deletions src/Microsoft.TestPlatform.Client/Execution/TestRunRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,10 @@ public void Abort()
}
}

// REVIEW: Added this, review this change. If we call abort, the event is never set, and we end up waiting for it to complete forever.
// I think w
nohwnd marked this conversation as resolved.
Show resolved Hide resolved
_runCompletionEvent.Set();

EqtTrace.Info("TestRunRequest.Abort: Aborted.");
}

Expand Down
1 change: 1 addition & 0 deletions src/Microsoft.TestPlatform.Client/Friends.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@
#region Test Assemblies

[assembly: InternalsVisibleTo("Microsoft.TestPlatform.Client.UnitTests, PublicKey=002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")]
[assembly: InternalsVisibleTo("vstest.ProgrammerTests, PublicKey=002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")]

#endregion
6 changes: 3 additions & 3 deletions src/Microsoft.TestPlatform.Client/TestPlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace Microsoft.VisualStudio.TestPlatform.Client;
/// </summary>
internal class TestPlatform : ITestPlatform
{
private readonly TestRuntimeProviderManager _testHostProviderManager;
private readonly ITestRuntimeProviderManager _testHostProviderManager;

private readonly IFileHelper _fileHelper;

Expand Down Expand Up @@ -64,10 +64,10 @@ public TestPlatform()
/// <param name="testEngine">The test engine.</param>
/// <param name="filehelper">The file helper.</param>
/// <param name="testHostProviderManager">The data.</param>
protected TestPlatform(
internal TestPlatform(
ITestEngine testEngine,
IFileHelper filehelper,
TestRuntimeProviderManager testHostProviderManager)
ITestRuntimeProviderManager testHostProviderManager)
{
TestEngine = testEngine;
_fileHelper = filehelper;
Expand Down
2 changes: 2 additions & 0 deletions src/Microsoft.TestPlatform.Common/Friends.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,6 @@
[assembly: InternalsVisibleTo("Microsoft.TestPlatform.Extensions.BlameDataCollector.UnitTests, PublicKey=002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")]
[assembly: InternalsVisibleTo("Microsoft.TestPlatform.TestUtilities, PublicKey=002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")]
[assembly: InternalsVisibleTo("Microsoft.TestPlatform.AcceptanceTests, PublicKey=002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")]
[assembly: InternalsVisibleTo("vstest.ProgrammerTests, PublicKey=002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")]

#endregion
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Microsoft.VisualStudio.TestPlatform.ObjectModel.Host;
nohwnd marked this conversation as resolved.
Show resolved Hide resolved

namespace Microsoft.VisualStudio.TestPlatform.Common.Hosting;
internal interface ITestRuntimeProviderManager
{
ITestRuntimeProvider GetTestHostManagerByRunConfiguration(string runConfiguration);
ITestRuntimeProvider GetTestHostManagerByUri(string hostUri);
Evangelink marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Microsoft.VisualStudio.TestPlatform.Common.Hosting;
/// <summary>
/// Responsible for managing TestRuntimeProviderManager extensions
/// </summary>
public class TestRuntimeProviderManager
public class TestRuntimeProviderManager : ITestRuntimeProviderManager
{
#region Fields

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,15 @@ public static DataCollectionRequestHandler Create(
{
ValidateArg.NotNull(communicationManager, nameof(communicationManager));
ValidateArg.NotNull(messageSink, nameof(messageSink));
// TODO: The MessageSink and DataCollectionRequestHandler have circular dependency.
// Message sink is injected into this Create method and then into constructor
// and into the constructor of DataCollectionRequestHandler. Data collection manager
// is then assigned to .Instace (which unlike many other .Instance is not populated
// directly in that property, but is created here). And then MessageSink depends on
// the .Instance. This is a very complicated way of solving the circular dependency,
// and should be replaced by adding a property to Message and assigning it.
// .Instance can then be removed.

nohwnd marked this conversation as resolved.
Show resolved Hide resolved
if (Instance == null)
{
lock (SyncObject)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class ConnectedEventArgs : EventArgs
/// <summary>
/// Initializes a new instance of the <see cref="ConnectedEventArgs"/> class.
/// </summary>
// TODO: Do we need this constructor?
public ConnectedEventArgs()
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public interface ICommunicationEndPoint
event EventHandler<ConnectedEventArgs> Connected;

/// <summary>
/// Event raised when an endPoint is disconnected.
/// Event raised when an endPoint is disconnected on failure. It should not be notified when we are just closing the connection after success.
/// </summary>
event EventHandler<DisconnectedEventArgs> Disconnected;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ public class Message
/// <summary>
/// Gets or sets the payload.
/// </summary>
// TODO: Our public contract says that we should be able to communicate over JSON, but we should not be stopping ourselves from
// negotiating a different protocol. Or using a different serialization library than NewtonsoftJson. Check why this is published as JToken
// and not as a string.
public JToken Payload { get; set; }

/// <summary>
Expand All @@ -27,6 +30,8 @@ public class Message
/// <returns> The <see cref="string"/>. </returns>
public override string ToString()
{
// TODO: Review where this is used, we should avoid extensive serialization and deserialization,
// and this might be happening in multiple places that are not the edge of our process.
return "(" + MessageType + ") -> " + (Payload == null ? "null" : Payload.ToString(Formatting.Indented));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,17 +100,17 @@ private void OnServerConnected(Task connectAsyncTask)
// Start the message loop
Task.Run(() => _tcpClient.MessageLoopAsync(
_channel,
Stop,
StopOnError,
_cancellation.Token))
.ConfigureAwait(false);
}
}
}

private void Stop(Exception error)
private void StopOnError(Exception error)
{
EqtTrace.Info("SocketClient.PrivateStop: Stop communication from server endpoint: {0}, error:{1}", _endPoint, error);

// TODO: this is here to prevent stack overflow.
nohwnd marked this conversation as resolved.
Show resolved Hide resolved
if (!_stopped)
{
// Do not allow stop to be called multiple times.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,16 @@ private void OnClientConnected(TcpClient client)
}

// Start the message loop
Task.Run(() => _tcpClient.MessageLoopAsync(_channel, error => Stop(error), _cancellation.Token)).ConfigureAwait(false);
Task.Run(() => _tcpClient.MessageLoopAsync(_channel, error => StopOnError(error), _cancellation.Token)).ConfigureAwait(false);
}
}

private void Stop(Exception error)
/// <summary>
/// Stop the connection when error was encountered. Dispose all communication, and notify subscribers of Disconnected event
/// that we aborted.
/// </summary>
/// <param name="error"></param>
private void StopOnError(Exception error)
{
EqtTrace.Info("SocketServer.PrivateStop: Stopping server endPoint: {0} error: {1}", _endPoint, error);

Expand Down
Loading