-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Show currently running tests in dotnet test MTP output (#49712) #54486
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
src/Cli/dotnet/Commands/Test/MTP/IPC/Models/TestInProgressMessages.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| namespace Microsoft.DotNet.Cli.Commands.Test.IPC.Models; | ||
|
|
||
| internal sealed record TestInProgressMessage(string? Uid, string? DisplayName); | ||
|
|
||
| internal sealed record TestInProgressMessages(string? ExecutionId, string? InstanceId, TestInProgressMessage[] InProgressMessages) : IRequest; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
164 changes: 164 additions & 0 deletions
164
src/Cli/dotnet/Commands/Test/MTP/IPC/Serializers/TestInProgressMessagesSerializer.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,164 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System.Diagnostics; | ||
| using Microsoft.DotNet.Cli.Commands.Test.IPC.Models; | ||
|
|
||
| namespace Microsoft.DotNet.Cli.Commands.Test.IPC.Serializers; | ||
|
|
||
| /* | ||
| |---FieldCount---| 2 bytes | ||
|
|
||
| |---ExecutionId Id---| (2 bytes) | ||
| |---ExecutionId Size---| (4 bytes) | ||
| |---ExecutionId Value---| (n bytes) | ||
|
|
||
| |---InstanceId Id---| (2 bytes) | ||
| |---InstanceId Size---| (4 bytes) | ||
| |---InstanceId Value---| (n bytes) | ||
|
|
||
| |---TestInProgressMessageList Id---| (2 bytes) | ||
| |---TestInProgressMessageList Size---| (4 bytes) | ||
| |---TestInProgressMessageList Value---| (n bytes) | ||
| |---TestInProgressMessageList Length---| (4 bytes) | ||
|
|
||
| |---TestInProgressMessageList[0] FieldCount---| 2 bytes | ||
|
|
||
| |---TestInProgressMessageList[0].Uid Id---| (2 bytes) | ||
| |---TestInProgressMessageList[0].Uid Size---| (4 bytes) | ||
| |---TestInProgressMessageList[0].Uid Value---| (n bytes) | ||
|
|
||
| |---TestInProgressMessageList[0].DisplayName Id---| (2 bytes) | ||
| |---TestInProgressMessageList[0].DisplayName Size---| (4 bytes) | ||
| |---TestInProgressMessageList[0].DisplayName Value---| (n bytes) | ||
| */ | ||
|
|
||
| internal sealed class TestInProgressMessagesSerializer : BaseSerializer, INamedPipeSerializer | ||
| { | ||
| public int Id => TestInProgressMessagesFieldsId.MessagesSerializerId; | ||
|
|
||
| public object Deserialize(Stream stream) | ||
| { | ||
| string? executionId = null; | ||
| string? instanceId = null; | ||
| List<TestInProgressMessage>? inProgressMessages = null; | ||
|
|
||
| ushort fieldCount = ReadUShort(stream); | ||
|
|
||
| for (int i = 0; i < fieldCount; i++) | ||
| { | ||
| int fieldId = ReadUShort(stream); | ||
| int fieldSize = ReadInt(stream); | ||
|
|
||
| switch (fieldId) | ||
| { | ||
| case TestInProgressMessagesFieldsId.ExecutionId: | ||
| executionId = ReadStringValue(stream, fieldSize); | ||
| break; | ||
|
|
||
| case TestInProgressMessagesFieldsId.InstanceId: | ||
| instanceId = ReadStringValue(stream, fieldSize); | ||
| break; | ||
|
|
||
| case TestInProgressMessagesFieldsId.TestInProgressMessageList: | ||
| inProgressMessages = ReadInProgressMessagesPayload(stream); | ||
| break; | ||
|
|
||
| default: | ||
| // If we don't recognize the field id, skip the payload corresponding to that field | ||
| SetPosition(stream, stream.Position + fieldSize); | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| return new TestInProgressMessages(executionId, instanceId, inProgressMessages is null ? [] : [.. inProgressMessages]); | ||
| } | ||
|
|
||
| private static List<TestInProgressMessage> ReadInProgressMessagesPayload(Stream stream) | ||
| { | ||
| List<TestInProgressMessage> inProgressMessages = []; | ||
|
|
||
| int length = ReadInt(stream); | ||
| for (int i = 0; i < length; i++) | ||
| { | ||
| string? uid = null, displayName = null; | ||
|
|
||
| int fieldCount = ReadUShort(stream); | ||
|
|
||
| for (int j = 0; j < fieldCount; j++) | ||
| { | ||
| int fieldId = ReadUShort(stream); | ||
| int fieldSize = ReadInt(stream); | ||
|
|
||
| switch (fieldId) | ||
| { | ||
| case TestInProgressMessageFieldsId.Uid: | ||
| uid = ReadStringValue(stream, fieldSize); | ||
| break; | ||
|
|
||
| case TestInProgressMessageFieldsId.DisplayName: | ||
| displayName = ReadStringValue(stream, fieldSize); | ||
| break; | ||
|
|
||
| default: | ||
| SetPosition(stream, stream.Position + fieldSize); | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| inProgressMessages.Add(new TestInProgressMessage(uid, displayName)); | ||
| } | ||
|
|
||
| return inProgressMessages; | ||
| } | ||
|
|
||
| public void Serialize(object objectToSerialize, Stream stream) | ||
| { | ||
| Debug.Assert(stream.CanSeek, "We expect a seekable stream."); | ||
|
|
||
| var inProgressMessages = (TestInProgressMessages)objectToSerialize; | ||
|
|
||
| WriteUShort(stream, GetFieldCount(inProgressMessages)); | ||
|
|
||
| WriteField(stream, TestInProgressMessagesFieldsId.ExecutionId, inProgressMessages.ExecutionId); | ||
| WriteField(stream, TestInProgressMessagesFieldsId.InstanceId, inProgressMessages.InstanceId); | ||
| WriteInProgressMessagesPayload(stream, inProgressMessages.InProgressMessages); | ||
| } | ||
|
|
||
| private static void WriteInProgressMessagesPayload(Stream stream, TestInProgressMessage[]? inProgressMessageList) | ||
| { | ||
| if (inProgressMessageList is null || inProgressMessageList.Length == 0) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| WriteUShort(stream, TestInProgressMessagesFieldsId.TestInProgressMessageList); | ||
|
|
||
| // We will reserve an int (4 bytes) | ||
| // so that we fill the size later, once we write the payload | ||
| WriteInt(stream, 0); | ||
|
|
||
| long before = stream.Position; | ||
| WriteInt(stream, inProgressMessageList.Length); | ||
| foreach (TestInProgressMessage inProgressMessage in inProgressMessageList) | ||
| { | ||
| WriteUShort(stream, GetFieldCount(inProgressMessage)); | ||
|
|
||
| WriteField(stream, TestInProgressMessageFieldsId.Uid, inProgressMessage.Uid); | ||
| WriteField(stream, TestInProgressMessageFieldsId.DisplayName, inProgressMessage.DisplayName); | ||
| } | ||
|
|
||
| // NOTE: We are able to seek only if we are using a MemoryStream | ||
| // thus, the seek operation is fast as we are only changing the value of a property | ||
| WriteAtPosition(stream, (int)(stream.Position - before), before - sizeof(int)); | ||
| } | ||
|
|
||
| private static ushort GetFieldCount(TestInProgressMessages inProgressMessages) => | ||
| (ushort)((inProgressMessages.ExecutionId is null ? 0 : 1) + | ||
| (inProgressMessages.InstanceId is null ? 0 : 1) + | ||
| (IsNullOrEmpty(inProgressMessages.InProgressMessages) ? 0 : 1)); | ||
|
|
||
| private static ushort GetFieldCount(TestInProgressMessage inProgressMessage) => | ||
| (ushort)((inProgressMessage.Uid is null ? 0 : 1) + | ||
| (inProgressMessage.DisplayName is null ? 0 : 1)); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.