Deduplicate test result deserialization logic#9819
Merged
Evangelink merged 2 commits intoJul 10, 2026
Conversation
Extract shared helpers in TestResultMessagesSerializer so the common test result fields are read and written once instead of being duplicated across the successful and failed message paths. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Refactors test-result IPC serialization to remove duplicated common-field handling while preserving the wire format.
Changes:
- Centralizes common result-field deserialization.
- Shares leading-field serialization.
- Retains explicit failed-result exception handling.
Show a summary per file
| File | Description |
|---|---|
TestResultMessagesSerializer.cs |
Extracts shared read/write helpers and accumulator state. |
Review details
- Files reviewed: 1/1 changed files
- Comments generated: 1
- Review effort level: Medium
Contributor
There was a problem hiding this comment.
Note
🤖 Automated review by GitHub Copilot. Generated by the Expert Code Review workflow. To request a follow-up action, reply by tagging @copilot directly.
Review Summary
Clean refactoring — no issues found across any applicable dimension.
Verdict Table
| # | Dimension | Verdict |
|---|---|---|
| 1 | Algorithmic Correctness | ✅ Pass — Field IDs 1–5 are identical for both SuccessfulTestResultMessageFieldsId and FailedTestResultMessageFieldsId (confirmed in ObjectFieldIds.cs). The differing IDs (StandardOutput, ErrorOutput, SessionUid) are correctly parameterized. Wire format is preserved exactly. |
| 2 | Edge Cases & Defensive Coding | ✅ N/A — No new edge-case-sensitive code; existing null handling unchanged. |
| 3 | Concurrency & Thread Safety | ✅ N/A — CommonTestResultFields is allocated per-iteration and never shared across threads. |
| 4 | Performance & Allocations | ✅ Pass — One small CommonTestResultFields allocation per result message replaces the equivalent local variables. The delegate in ReadSuccessfulTestMessagesPayload now captures fields + 3 constants, comparable to the original closure. No regression. |
| 5 | API Design & Public Surface | ✅ N/A — All new members are private/private sealed class. No public API change. |
| 6 | Backward & Forward Compatibility | ✅ Pass — Wire format is identical; field IDs and write order preserved. IPC contract stability maintained. |
| 7 | Cross-TFM Correctness | ✅ N/A — No TFM-specific code paths introduced. |
| 8 | Error Handling & Diagnostics | ✅ N/A — No new error paths. |
| 9 | Security | ✅ N/A |
| 10 | Resource Management | ✅ N/A |
| 11 | Localization | ✅ N/A |
| 12 | Naming & Conventions | ✅ Pass — CommonTestResultFields, TryReadCommonTestResultField, WriteCommonTestResultLeadingFields follow repo conventions. |
| 13 | Code Style | ✅ Pass — Consistent with surrounding code. |
| 14 | Documentation & Comments | ✅ Pass — Both helper methods have clear comments explaining the field-ID invariant and why parameters are needed. |
| 15 | Test Coverage | ✅ N/A — Pure refactoring with no behavioral change; existing serialization tests cover correctness. |
| 16 | Serialization & Wire Formats | ✅ Pass — Key dimension for this PR. Verified against ObjectFieldIds.cs that the shared constants produce identical bytes. |
| 17 | MSBuild & Build Infrastructure | ✅ N/A |
| 18 | Analyzers & Code Fixes | ✅ N/A |
| 19 | Configuration & Options | ✅ N/A |
| 20 | Logging & Telemetry | ✅ N/A |
| 21 | Scope Discipline | ✅ Pass — Single concern (deduplication), no unrelated changes. |
| 22 | PublicAPI.*.txt |
✅ N/A — No public API changes. |
LGTM — well-structured deduplication with good comments documenting the shared field-ID invariant.
…ation Address review feedback: CommonTestResultFields is now a struct captured by the reading closure and passed by ref, removing the extra per-message heap allocation on the deserialization hot path. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #9811.
Summary
ReadSuccessfulTestMessagesPayloadandReadFailedTestMessagesPayloadinTestResultMessagesSerializer.cscontained nearly identical deserialization logic, and the matching write methods duplicated the commonWriteFieldcalls. This PR extracts shared helpers so the common test result fields are read and written once.Changes
CommonTestResultFieldsmutable holder for the fields shared by successful and failed test result messages.TryReadCommonTestResultField, which handles the eight common fields during reads. TheUid,DisplayName,State,DurationandReasonfield ids are identical for both message types and are matched directly; theStandardOutput,ErrorOutputandSessionUidids differ (a failed message insertsExceptionMessageListbefore them on the wire), so they are passed in by the caller.WriteCommonTestResultLeadingFieldsfor the shared leading write fields.ReadFailedTestMessagesPayloadstill handles its extraExceptionMessageListfield explicitly before delegating to the shared helper.Wire format
No wire-format changes. Field ids and write order are preserved exactly, so the serialized bytes are identical.
Verification
Microsoft.Testing.Platform(0 warnings, 0 errors).Microsoft.Testing.Platform.DotnetTestProtocolContract.UnitTests: 21/21 passed.ProtocolTests+ProtocolEdgeCaseTests: 33/33 passed.