Skip to content

Commit

Permalink
Handle Execution ID in dotnet test (#42863)
Browse files Browse the repository at this point in the history
  • Loading branch information
mariam-abdulla authored Aug 21, 2024
1 parent 3634b7e commit 3083717
Show file tree
Hide file tree
Showing 15 changed files with 157 additions and 106 deletions.
36 changes: 16 additions & 20 deletions src/Cli/dotnet/commands/dotnet-test/CliConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,34 +20,30 @@ internal static class CliConstants

internal static class TestStates
{
internal const string Passed = "Passed";

internal const string Skipped = "Skipped";

internal const string Failed = "Failed";

internal const string Error = "Error";

internal const string Timeout = "Timeout";

internal const string Cancelled = "Cancelled";
internal const byte Passed = 0;
internal const byte Skipped = 1;
internal const byte Failed = 2;
internal const byte Error = 3;
internal const byte Timeout = 4;
internal const byte Cancelled = 5;
}

internal static class SessionEventTypes
{
internal const string TestSessionStart = "TestSessionStart";
internal const string TestSessionEnd = "TestSessionEnd";
internal const byte TestSessionStart = 0;
internal const byte TestSessionEnd = 1;
}

internal static class HandshakeInfoPropertyNames
{
internal const string PID = "PID";
internal const string Architecture = "Architecture";
internal const string Framework = "Framework";
internal const string OS = "OS";
internal const string ProtocolVersion = "ProtocolVersion";
internal const string HostType = "HostType";
internal const string ModulePath = "ModulePath";
internal const byte PID = 0;
internal const byte Architecture = 1;
internal const byte Framework = 2;
internal const byte OS = 3;
internal const byte ProtocolVersion = 4;
internal const byte HostType = 5;
internal const byte ModulePath = 6;
internal const byte ExecutionId = 7;
}

internal static class ProtocolConstants
Expand Down
6 changes: 6 additions & 0 deletions src/Cli/dotnet/commands/dotnet-test/CustomEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,10 @@ internal class TestProcessExitEventArgs : EventArgs
public List<string> ErrorData { get; set; }
public int ExitCode { get; set; }
}

internal class ExecutionEventArgs : EventArgs
{
public string ModulePath { get; set; }
public string ExecutionId { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@

namespace Microsoft.DotNet.Tools.Test
{
internal sealed record FileArtifactInfo(string? FullPath, string? DisplayName, string? Description, string? TestUid, string? TestDisplayName, string? SessionUid, string? ModulePath) : IRequest;
internal sealed record FileArtifactInfo(string? FullPath, string? DisplayName, string? Description, string? TestUid, string? TestDisplayName, string? SessionUid, string? ExecutionId) : IRequest;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@

namespace Microsoft.DotNet.Tools.Test
{
internal sealed record HandshakeInfo(Dictionary<string, string>? Properties) : IRequest, IResponse;
internal sealed record HandshakeInfo(Dictionary<byte, string>? Properties) : IRequest, IResponse;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace Microsoft.DotNet.Tools.Test
{
internal sealed record SuccessfulTestResultMessage(string? Uid, string? DisplayName, string? State, string? Reason, string? SessionUid, string? ModulePath) : IRequest;
internal sealed record SuccessfulTestResultMessage(string? Uid, string? DisplayName, byte? State, string? Reason, string? SessionUid, string? ExecutionId) : IRequest;

internal sealed record FailedTestResultMessage(string? Uid, string? DisplayName, string? State, string? Reason, string? ErrorMessage, string? ErrorStackTrace, string? SessionUid, string? ModulePath) : IRequest;
internal sealed record FailedTestResultMessage(string? Uid, string? DisplayName, byte? State, string? Reason, string? ErrorMessage, string? ErrorStackTrace, string? SessionUid, string? ExecutionId) : IRequest;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@

namespace Microsoft.DotNet.Tools.Test
{
internal sealed record TestSessionEvent(string? SessionType, string? SessionUid, string? ModulePath) : IRequest;
internal sealed record TestSessionEvent(byte? SessionType, string? SessionUid, string? ExecutionId) : IRequest;
}
8 changes: 4 additions & 4 deletions src/Cli/dotnet/commands/dotnet-test/IPC/ObjectFieldIds.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ internal static class SuccessfulTestResultMessageFieldsId
internal const int State = 3;
internal const int Reason = 4;
internal const int SessionUid = 5;
internal const int ModulePath = 6;
internal const int ExecutionId = 6;
}

internal static class FailedTestResultMessageFieldsId
Expand All @@ -40,7 +40,7 @@ internal static class FailedTestResultMessageFieldsId
internal const int ErrorMessage = 5;
internal const int ErrorStackTrace = 6;
internal const int SessionUid = 7;
internal const int ModulePath = 8;
internal const int ExecutionId = 8;
}

internal static class FileArtifactInfoFieldsId
Expand All @@ -51,13 +51,13 @@ internal static class FileArtifactInfoFieldsId
internal const int TestUid = 4;
internal const int TestDisplayName = 5;
internal const int SessionUid = 6;
internal const int ModulePath = 7;
internal const int ExecutionId = 7;
}

internal static class TestSessionEventFieldsId
{
internal const int SessionType = 1;
internal const int SessionUid = 2;
internal const int ModulePath = 3;
internal const int ExecutionId = 3;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,10 @@ protected static bool ReadBool(Stream stream)
}
#endif

protected static byte ReadByte(Stream stream) => (byte)stream.ReadByte();

protected static void WriteByte(Stream stream, byte value) => stream.WriteByte(value);

protected static void WriteField(Stream stream, ushort id, string? value)
{
if (value is null)
Expand All @@ -238,6 +242,16 @@ protected static void WriteField(Stream stream, string? value)
WriteString(stream, value);
}

protected static void WriteField(Stream stream, byte? value)
{
if (value is null)
{
return;
}

WriteByte(stream, value.Value);
}

protected static void WriteField(Stream stream, ushort id, bool? value)
{
if (value is null)
Expand All @@ -250,6 +264,18 @@ protected static void WriteField(Stream stream, ushort id, bool? value)
WriteBool(stream, value.Value);
}

protected static void WriteField(Stream stream, ushort id, byte? value)
{
if (value is null)
{
return;
}

WriteShort(stream, id);
WriteSize<bool>(stream);
WriteByte(stream, value.Value);
}

protected static void SetPosition(Stream stream, long position) => stream.Position = position;

protected static void WriteAtPosition(Stream stream, int value, long position)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,30 @@ namespace Microsoft.DotNet.Tools.Test
/*
|---FieldCount---| 2 bytes
|---ModuleName Id---| 1 (2 bytes)
|---ModuleName Id---| (2 bytes)
|---ModuleName Size---| (4 bytes)
|---ModuleName Value---| (n bytes)
|---CommandLineOptionMessageList Id---| 2 (2 bytes)
|---CommandLineOptionMessageList Id---| (2 bytes)
|---CommandLineOptionMessageList Size---| (4 bytes)
|---CommandLineOptionMessageList Value---| (n bytes)
|---CommandLineOptionMessageList Length---| (4 bytes)
|---CommandLineOptionMessageList[0] FieldCount---| 2 bytes
|---CommandLineOptionMessageList[0] Name Id---| 1 (2 bytes)
|---CommandLineOptionMessageList[0] Name Id---| (2 bytes)
|---CommandLineOptionMessageList[0] Name Size---| (4 bytes)
|---CommandLineOptionMessageList[0] Name Value---| (n bytes)
|---CommandLineOptionMessageList[1] Description Id---| 2 (2 bytes)
|---CommandLineOptionMessageList[1] Description Id---| (2 bytes)
|---CommandLineOptionMessageList[1] Description Size---| (4 bytes)
|---CommandLineOptionMessageList[1] Description Value---| (n bytes)
|---CommandLineOptionMessageList[3] IsHidden Id---| 4 (2 bytes)
|---CommandLineOptionMessageList[3] IsHidden Id---| (2 bytes)
|---CommandLineOptionMessageList[3] IsHidden Size---| (4 bytes)
|---CommandLineOptionMessageList[3] IsHidden Value---| (1 byte)
|---CommandLineOptionMessageList[4] IsBuiltIn Id---| 5 (2 bytes)
|---CommandLineOptionMessageList[4] IsBuiltIn Id---| (2 bytes)
|---CommandLineOptionMessageList[4] IsBuiltIn Size---| (4 bytes)
|---CommandLineOptionMessageList[4] IsBuiltIn Value---| (1 byte)
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,33 @@ namespace Microsoft.DotNet.Tools.Test
/*
|---FieldCount---| 2 bytes
|---File FullPath Id---| 1 (2 bytes)
|---File FullPath Id---| (2 bytes)
|---File FullPath Size---| (4 bytes)
|---File FullPath Value---| (n bytes)
|---File DisplayName Id---| 1 (2 bytes)
|---File DisplayName Id---| (2 bytes)
|---File DisplayName Size---| (4 bytes)
|---File DisplayName Value---| (n bytes)
|---File Description Id---| 1 (2 bytes)
|---File Description Id---| (2 bytes)
|---File Description Size---| (4 bytes)
|---File Description Value---| (n bytes)
|---File TestUid Id---| 1 (2 bytes)
|---File TestUid Id---| (2 bytes)
|---File TestUid Size---| (4 bytes)
|---File TestUid Value---| (n bytes)
|---File TestDisplayName Id---| 1 (2 bytes)
|---File TestDisplayName Id---| (2 bytes)
|---File TestDisplayName Size---| (4 bytes)
|---File TestDisplayName Value---| (n bytes)
|---File SessionUid Id---| 1 (2 bytes)
|---File SessionUid Id---| (2 bytes)
|---File SessionUid Size---| (4 bytes)
|---File SessionUid Value---| (n bytes)
|---File ModulePath Id---| 1 (2 bytes)
|---File ModulePath Size---| (4 bytes)
|---File ModulePath Value---| (n bytes)
|---File ExecutionId Id---| (2 bytes)
|---File ExecutionId Size---| (4 bytes)
|---File ExecutionId Value---| (n bytes)
*/

internal sealed class FileArtifactInfoSerializer : BaseSerializer, INamedPipeSerializer
Expand All @@ -51,7 +51,7 @@ public object Deserialize(Stream stream)
string? testUid = null;
string? testDisplayName = null;
string? sessionUid = null;
string? modulePath = null;
string? executionId = null;

ushort fieldCount = ReadShort(stream);

Expand Down Expand Up @@ -86,8 +86,8 @@ public object Deserialize(Stream stream)
sessionUid = ReadString(stream);
break;

case FileArtifactInfoFieldsId.ModulePath:
modulePath = ReadString(stream);
case FileArtifactInfoFieldsId.ExecutionId:
executionId = ReadString(stream);
break;

default:
Expand All @@ -97,7 +97,7 @@ public object Deserialize(Stream stream)
}
}

return new FileArtifactInfo(fullPath, displayName, description, testUid, testDisplayName, sessionUid, modulePath);
return new FileArtifactInfo(fullPath, displayName, description, testUid, testDisplayName, sessionUid, executionId);
}

public void Serialize(object objectToSerialize, Stream stream)
Expand All @@ -114,7 +114,8 @@ public void Serialize(object objectToSerialize, Stream stream)
WriteField(stream, FileArtifactInfoFieldsId.TestUid, fileArtifactInfo.TestUid);
WriteField(stream, FileArtifactInfoFieldsId.TestDisplayName, fileArtifactInfo.TestDisplayName);
WriteField(stream, FileArtifactInfoFieldsId.SessionUid, fileArtifactInfo.SessionUid);
WriteField(stream, FileArtifactInfoFieldsId.ModulePath, fileArtifactInfo.ModulePath);
WriteField(stream, FileArtifactInfoFieldsId.ExecutionId, fileArtifactInfo.ExecutionId);

}

private static ushort GetFieldCount(FileArtifactInfo fileArtifactInfo) =>
Expand All @@ -124,6 +125,6 @@ private static ushort GetFieldCount(FileArtifactInfo fileArtifactInfo) =>
(fileArtifactInfo.TestUid is null ? 0 : 1) +
(fileArtifactInfo.TestDisplayName is null ? 0 : 1) +
(fileArtifactInfo.SessionUid is null ? 0 : 1) +
(fileArtifactInfo.ModulePath is null ? 0 : 1));
(fileArtifactInfo.ExecutionId is null ? 0 : 1));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ internal sealed class HandshakeInfoSerializer : BaseSerializer, INamedPipeSerial

public object Deserialize(Stream stream)
{
Dictionary<string, string> properties = new();
Dictionary<byte, string> properties = new();

ushort fieldCount = ReadShort(stream);

for (int i = 0; i < fieldCount; i++)
{
properties.Add(ReadString(stream), ReadString(stream));
properties.Add(ReadByte(stream), ReadString(stream));
}

return new HandshakeInfo(properties);
Expand All @@ -35,7 +35,7 @@ public void Serialize(object objectToSerialize, Stream stream)
}

WriteShort(stream, (ushort)handshakeInfo.Properties.Count);
foreach (KeyValuePair<string, string> property in handshakeInfo.Properties)
foreach (KeyValuePair<byte, string> property in handshakeInfo.Properties)
{
WriteField(stream, property.Key);
WriteField(stream, property.Value);
Expand Down
Loading

0 comments on commit 3083717

Please sign in to comment.