Skip to content

Deduplicate test result deserialization logic#9819

Merged
Evangelink merged 2 commits into
mainfrom
dev/amauryleve/dedup-test-result-deserialization
Jul 10, 2026
Merged

Deduplicate test result deserialization logic#9819
Evangelink merged 2 commits into
mainfrom
dev/amauryleve/dedup-test-result-deserialization

Conversation

@Evangelink

Copy link
Copy Markdown
Member

Fixes #9811.

Summary

ReadSuccessfulTestMessagesPayload and ReadFailedTestMessagesPayload in TestResultMessagesSerializer.cs contained nearly identical deserialization logic, and the matching write methods duplicated the common WriteField calls. This PR extracts shared helpers so the common test result fields are read and written once.

Changes

  • Added a private CommonTestResultFields mutable holder for the fields shared by successful and failed test result messages.
  • Added TryReadCommonTestResultField, which handles the eight common fields during reads. The Uid, DisplayName, State, Duration and Reason field ids are identical for both message types and are matched directly; the StandardOutput, ErrorOutput and SessionUid ids differ (a failed message inserts ExceptionMessageList before them on the wire), so they are passed in by the caller.
  • Added WriteCommonTestResultLeadingFields for the shared leading write fields.
  • ReadFailedTestMessagesPayload still handles its extra ExceptionMessageList field 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

  • Built Microsoft.Testing.Platform (0 warnings, 0 errors).
  • Microsoft.Testing.Platform.DotnetTestProtocolContract.UnitTests: 21/21 passed.
  • ProtocolTests + ProtocolEdgeCaseTests: 33/33 passed.

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>
Copilot AI review requested due to automatic review settings July 10, 2026 09:34

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
Copilot AI review requested due to automatic review settings July 10, 2026 12:58

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review details

  • Files reviewed: 1/1 changed files
  • Comments generated: 0 new
  • Review effort level: Medium

@Evangelink Evangelink merged commit cd514fc into main Jul 10, 2026
30 of 33 checks passed
@Evangelink Evangelink deleted the dev/amauryleve/dedup-test-result-deserialization branch July 10, 2026 13:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[duplicate-code] Duplicate Deserialization Logic in SuccessfulTestResultMessage and FailedTestResultMessage

2 participants