Skip to content

Commit 3083717

Browse files
Handle Execution ID in dotnet test (#42863)
1 parent 3634b7e commit 3083717

15 files changed

+157
-106
lines changed

src/Cli/dotnet/commands/dotnet-test/CliConstants.cs

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,34 +20,30 @@ internal static class CliConstants
2020

2121
internal static class TestStates
2222
{
23-
internal const string Passed = "Passed";
24-
25-
internal const string Skipped = "Skipped";
26-
27-
internal const string Failed = "Failed";
28-
29-
internal const string Error = "Error";
30-
31-
internal const string Timeout = "Timeout";
32-
33-
internal const string Cancelled = "Cancelled";
23+
internal const byte Passed = 0;
24+
internal const byte Skipped = 1;
25+
internal const byte Failed = 2;
26+
internal const byte Error = 3;
27+
internal const byte Timeout = 4;
28+
internal const byte Cancelled = 5;
3429
}
3530

3631
internal static class SessionEventTypes
3732
{
38-
internal const string TestSessionStart = "TestSessionStart";
39-
internal const string TestSessionEnd = "TestSessionEnd";
33+
internal const byte TestSessionStart = 0;
34+
internal const byte TestSessionEnd = 1;
4035
}
4136

4237
internal static class HandshakeInfoPropertyNames
4338
{
44-
internal const string PID = "PID";
45-
internal const string Architecture = "Architecture";
46-
internal const string Framework = "Framework";
47-
internal const string OS = "OS";
48-
internal const string ProtocolVersion = "ProtocolVersion";
49-
internal const string HostType = "HostType";
50-
internal const string ModulePath = "ModulePath";
39+
internal const byte PID = 0;
40+
internal const byte Architecture = 1;
41+
internal const byte Framework = 2;
42+
internal const byte OS = 3;
43+
internal const byte ProtocolVersion = 4;
44+
internal const byte HostType = 5;
45+
internal const byte ModulePath = 6;
46+
internal const byte ExecutionId = 7;
5147
}
5248

5349
internal static class ProtocolConstants

src/Cli/dotnet/commands/dotnet-test/CustomEventArgs.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,10 @@ internal class TestProcessExitEventArgs : EventArgs
4646
public List<string> ErrorData { get; set; }
4747
public int ExitCode { get; set; }
4848
}
49+
50+
internal class ExecutionEventArgs : EventArgs
51+
{
52+
public string ModulePath { get; set; }
53+
public string ExecutionId { get; set; }
54+
}
4955
}

src/Cli/dotnet/commands/dotnet-test/IPC/Models/FileArtifactInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55

66
namespace Microsoft.DotNet.Tools.Test
77
{
8-
internal sealed record FileArtifactInfo(string? FullPath, string? DisplayName, string? Description, string? TestUid, string? TestDisplayName, string? SessionUid, string? ModulePath) : IRequest;
8+
internal sealed record FileArtifactInfo(string? FullPath, string? DisplayName, string? Description, string? TestUid, string? TestDisplayName, string? SessionUid, string? ExecutionId) : IRequest;
99
}

src/Cli/dotnet/commands/dotnet-test/IPC/Models/HandshakeInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55

66
namespace Microsoft.DotNet.Tools.Test
77
{
8-
internal sealed record HandshakeInfo(Dictionary<string, string>? Properties) : IRequest, IResponse;
8+
internal sealed record HandshakeInfo(Dictionary<byte, string>? Properties) : IRequest, IResponse;
99
}

src/Cli/dotnet/commands/dotnet-test/IPC/Models/TestResultMessage.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

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

10-
internal sealed record FailedTestResultMessage(string? Uid, string? DisplayName, string? State, string? Reason, string? ErrorMessage, string? ErrorStackTrace, string? SessionUid, string? ModulePath) : IRequest;
10+
internal sealed record FailedTestResultMessage(string? Uid, string? DisplayName, byte? State, string? Reason, string? ErrorMessage, string? ErrorStackTrace, string? SessionUid, string? ExecutionId) : IRequest;
1111
}

src/Cli/dotnet/commands/dotnet-test/IPC/Models/TestSessionEvent.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55

66
namespace Microsoft.DotNet.Tools.Test
77
{
8-
internal sealed record TestSessionEvent(string? SessionType, string? SessionUid, string? ModulePath) : IRequest;
8+
internal sealed record TestSessionEvent(byte? SessionType, string? SessionUid, string? ExecutionId) : IRequest;
99
}

src/Cli/dotnet/commands/dotnet-test/IPC/ObjectFieldIds.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ internal static class SuccessfulTestResultMessageFieldsId
2828
internal const int State = 3;
2929
internal const int Reason = 4;
3030
internal const int SessionUid = 5;
31-
internal const int ModulePath = 6;
31+
internal const int ExecutionId = 6;
3232
}
3333

3434
internal static class FailedTestResultMessageFieldsId
@@ -40,7 +40,7 @@ internal static class FailedTestResultMessageFieldsId
4040
internal const int ErrorMessage = 5;
4141
internal const int ErrorStackTrace = 6;
4242
internal const int SessionUid = 7;
43-
internal const int ModulePath = 8;
43+
internal const int ExecutionId = 8;
4444
}
4545

4646
internal static class FileArtifactInfoFieldsId
@@ -51,13 +51,13 @@ internal static class FileArtifactInfoFieldsId
5151
internal const int TestUid = 4;
5252
internal const int TestDisplayName = 5;
5353
internal const int SessionUid = 6;
54-
internal const int ModulePath = 7;
54+
internal const int ExecutionId = 7;
5555
}
5656

5757
internal static class TestSessionEventFieldsId
5858
{
5959
internal const int SessionType = 1;
6060
internal const int SessionUid = 2;
61-
internal const int ModulePath = 3;
61+
internal const int ExecutionId = 3;
6262
}
6363
}

src/Cli/dotnet/commands/dotnet-test/IPC/Serializers/BaseSerializer.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,10 @@ protected static bool ReadBool(Stream stream)
216216
}
217217
#endif
218218

219+
protected static byte ReadByte(Stream stream) => (byte)stream.ReadByte();
220+
221+
protected static void WriteByte(Stream stream, byte value) => stream.WriteByte(value);
222+
219223
protected static void WriteField(Stream stream, ushort id, string? value)
220224
{
221225
if (value is null)
@@ -238,6 +242,16 @@ protected static void WriteField(Stream stream, string? value)
238242
WriteString(stream, value);
239243
}
240244

245+
protected static void WriteField(Stream stream, byte? value)
246+
{
247+
if (value is null)
248+
{
249+
return;
250+
}
251+
252+
WriteByte(stream, value.Value);
253+
}
254+
241255
protected static void WriteField(Stream stream, ushort id, bool? value)
242256
{
243257
if (value is null)
@@ -250,6 +264,18 @@ protected static void WriteField(Stream stream, ushort id, bool? value)
250264
WriteBool(stream, value.Value);
251265
}
252266

267+
protected static void WriteField(Stream stream, ushort id, byte? value)
268+
{
269+
if (value is null)
270+
{
271+
return;
272+
}
273+
274+
WriteShort(stream, id);
275+
WriteSize<bool>(stream);
276+
WriteByte(stream, value.Value);
277+
}
278+
253279
protected static void SetPosition(Stream stream, long position) => stream.Position = position;
254280

255281
protected static void WriteAtPosition(Stream stream, int value, long position)

src/Cli/dotnet/commands/dotnet-test/IPC/Serializers/CommandLineOptionMessagesSerializer.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,30 +12,30 @@ namespace Microsoft.DotNet.Tools.Test
1212
/*
1313
|---FieldCount---| 2 bytes
1414
15-
|---ModuleName Id---| 1 (2 bytes)
15+
|---ModuleName Id---| (2 bytes)
1616
|---ModuleName Size---| (4 bytes)
1717
|---ModuleName Value---| (n bytes)
1818
19-
|---CommandLineOptionMessageList Id---| 2 (2 bytes)
19+
|---CommandLineOptionMessageList Id---| (2 bytes)
2020
|---CommandLineOptionMessageList Size---| (4 bytes)
2121
|---CommandLineOptionMessageList Value---| (n bytes)
2222
|---CommandLineOptionMessageList Length---| (4 bytes)
2323
2424
|---CommandLineOptionMessageList[0] FieldCount---| 2 bytes
2525
26-
|---CommandLineOptionMessageList[0] Name Id---| 1 (2 bytes)
26+
|---CommandLineOptionMessageList[0] Name Id---| (2 bytes)
2727
|---CommandLineOptionMessageList[0] Name Size---| (4 bytes)
2828
|---CommandLineOptionMessageList[0] Name Value---| (n bytes)
2929
30-
|---CommandLineOptionMessageList[1] Description Id---| 2 (2 bytes)
30+
|---CommandLineOptionMessageList[1] Description Id---| (2 bytes)
3131
|---CommandLineOptionMessageList[1] Description Size---| (4 bytes)
3232
|---CommandLineOptionMessageList[1] Description Value---| (n bytes)
3333
34-
|---CommandLineOptionMessageList[3] IsHidden Id---| 4 (2 bytes)
34+
|---CommandLineOptionMessageList[3] IsHidden Id---| (2 bytes)
3535
|---CommandLineOptionMessageList[3] IsHidden Size---| (4 bytes)
3636
|---CommandLineOptionMessageList[3] IsHidden Value---| (1 byte)
3737
38-
|---CommandLineOptionMessageList[4] IsBuiltIn Id---| 5 (2 bytes)
38+
|---CommandLineOptionMessageList[4] IsBuiltIn Id---| (2 bytes)
3939
|---CommandLineOptionMessageList[4] IsBuiltIn Size---| (4 bytes)
4040
|---CommandLineOptionMessageList[4] IsBuiltIn Value---| (1 byte)
4141
*/

src/Cli/dotnet/commands/dotnet-test/IPC/Serializers/FileArtifactInfoSerializer.cs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,33 +10,33 @@ namespace Microsoft.DotNet.Tools.Test
1010
/*
1111
|---FieldCount---| 2 bytes
1212
13-
|---File FullPath Id---| 1 (2 bytes)
13+
|---File FullPath Id---| (2 bytes)
1414
|---File FullPath Size---| (4 bytes)
1515
|---File FullPath Value---| (n bytes)
1616
17-
|---File DisplayName Id---| 1 (2 bytes)
17+
|---File DisplayName Id---| (2 bytes)
1818
|---File DisplayName Size---| (4 bytes)
1919
|---File DisplayName Value---| (n bytes)
2020
21-
|---File Description Id---| 1 (2 bytes)
21+
|---File Description Id---| (2 bytes)
2222
|---File Description Size---| (4 bytes)
2323
|---File Description Value---| (n bytes)
2424
25-
|---File TestUid Id---| 1 (2 bytes)
25+
|---File TestUid Id---| (2 bytes)
2626
|---File TestUid Size---| (4 bytes)
2727
|---File TestUid Value---| (n bytes)
2828
29-
|---File TestDisplayName Id---| 1 (2 bytes)
29+
|---File TestDisplayName Id---| (2 bytes)
3030
|---File TestDisplayName Size---| (4 bytes)
3131
|---File TestDisplayName Value---| (n bytes)
3232
33-
|---File SessionUid Id---| 1 (2 bytes)
33+
|---File SessionUid Id---| (2 bytes)
3434
|---File SessionUid Size---| (4 bytes)
3535
|---File SessionUid Value---| (n bytes)
3636
37-
|---File ModulePath Id---| 1 (2 bytes)
38-
|---File ModulePath Size---| (4 bytes)
39-
|---File ModulePath Value---| (n bytes)
37+
|---File ExecutionId Id---| (2 bytes)
38+
|---File ExecutionId Size---| (4 bytes)
39+
|---File ExecutionId Value---| (n bytes)
4040
*/
4141

4242
internal sealed class FileArtifactInfoSerializer : BaseSerializer, INamedPipeSerializer
@@ -51,7 +51,7 @@ public object Deserialize(Stream stream)
5151
string? testUid = null;
5252
string? testDisplayName = null;
5353
string? sessionUid = null;
54-
string? modulePath = null;
54+
string? executionId = null;
5555

5656
ushort fieldCount = ReadShort(stream);
5757

@@ -86,8 +86,8 @@ public object Deserialize(Stream stream)
8686
sessionUid = ReadString(stream);
8787
break;
8888

89-
case FileArtifactInfoFieldsId.ModulePath:
90-
modulePath = ReadString(stream);
89+
case FileArtifactInfoFieldsId.ExecutionId:
90+
executionId = ReadString(stream);
9191
break;
9292

9393
default:
@@ -97,7 +97,7 @@ public object Deserialize(Stream stream)
9797
}
9898
}
9999

100-
return new FileArtifactInfo(fullPath, displayName, description, testUid, testDisplayName, sessionUid, modulePath);
100+
return new FileArtifactInfo(fullPath, displayName, description, testUid, testDisplayName, sessionUid, executionId);
101101
}
102102

103103
public void Serialize(object objectToSerialize, Stream stream)
@@ -114,7 +114,8 @@ public void Serialize(object objectToSerialize, Stream stream)
114114
WriteField(stream, FileArtifactInfoFieldsId.TestUid, fileArtifactInfo.TestUid);
115115
WriteField(stream, FileArtifactInfoFieldsId.TestDisplayName, fileArtifactInfo.TestDisplayName);
116116
WriteField(stream, FileArtifactInfoFieldsId.SessionUid, fileArtifactInfo.SessionUid);
117-
WriteField(stream, FileArtifactInfoFieldsId.ModulePath, fileArtifactInfo.ModulePath);
117+
WriteField(stream, FileArtifactInfoFieldsId.ExecutionId, fileArtifactInfo.ExecutionId);
118+
118119
}
119120

120121
private static ushort GetFieldCount(FileArtifactInfo fileArtifactInfo) =>
@@ -124,6 +125,6 @@ private static ushort GetFieldCount(FileArtifactInfo fileArtifactInfo) =>
124125
(fileArtifactInfo.TestUid is null ? 0 : 1) +
125126
(fileArtifactInfo.TestDisplayName is null ? 0 : 1) +
126127
(fileArtifactInfo.SessionUid is null ? 0 : 1) +
127-
(fileArtifactInfo.ModulePath is null ? 0 : 1));
128+
(fileArtifactInfo.ExecutionId is null ? 0 : 1));
128129
}
129130
}

0 commit comments

Comments
 (0)