-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Refactor Node IDs for taskhost to use record struct #12830
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
Open
Copilot
wants to merge
8
commits into
main
Choose a base branch
from
copilot/refactor-node-ids-taskhost
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+204
−58
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
61904bb
Initial plan
Copilot a74c8cb
Refactor Node IDs for taskhost to use TaskHostNodeKey record struct
Copilot 32f06e9
Fix communication node ID generation to use atomic increment instead …
Copilot 7acaea5
Simplify by removing intermediate _nodeIdToNodeKey dictionary
Copilot 306909c
Revert: Restore intermediate _nodeIdToNodeKey dictionary
Copilot 7eca3ed
Optimize packet routing with direct int lookups
Copilot 549d554
Address code review feedback
Copilot 38adb00
Update src/Build/BackEnd/Components/Communications/NodeProviderOutOfP…
JanProvaznik 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
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,116 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using Microsoft.Build.Internal; | ||
| using Shouldly; | ||
| using Xunit; | ||
|
|
||
| namespace Microsoft.Build.Engine.UnitTests.BackEnd | ||
| { | ||
| /// <summary> | ||
| /// Tests for TaskHostNodeKey record struct functionality. | ||
| /// </summary> | ||
| public class TaskHostNodeKey_Tests | ||
| { | ||
| [Fact] | ||
| public void TaskHostNodeKey_Equality_SameValues_AreEqual() | ||
| { | ||
| var key1 = new TaskHostNodeKey(HandshakeOptions.TaskHost | HandshakeOptions.NET, 1); | ||
| var key2 = new TaskHostNodeKey(HandshakeOptions.TaskHost | HandshakeOptions.NET, 1); | ||
|
|
||
| key1.ShouldBe(key2); | ||
| (key1 == key2).ShouldBeTrue(); | ||
| key1.GetHashCode().ShouldBe(key2.GetHashCode()); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void TaskHostNodeKey_Equality_DifferentNodeId_AreNotEqual() | ||
| { | ||
| var key1 = new TaskHostNodeKey(HandshakeOptions.TaskHost | HandshakeOptions.NET, 1); | ||
| var key2 = new TaskHostNodeKey(HandshakeOptions.TaskHost | HandshakeOptions.NET, 2); | ||
|
|
||
| key1.ShouldNotBe(key2); | ||
| (key1 != key2).ShouldBeTrue(); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void TaskHostNodeKey_Equality_DifferentHandshakeOptions_AreNotEqual() | ||
| { | ||
| var key1 = new TaskHostNodeKey(HandshakeOptions.TaskHost | HandshakeOptions.NET, 1); | ||
| var key2 = new TaskHostNodeKey(HandshakeOptions.TaskHost | HandshakeOptions.X64, 1); | ||
|
|
||
| key1.ShouldNotBe(key2); | ||
| (key1 != key2).ShouldBeTrue(); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void TaskHostNodeKey_CanBeUsedAsDictionaryKey() | ||
| { | ||
| var dict = new System.Collections.Generic.Dictionary<TaskHostNodeKey, string>(); | ||
| var key1 = new TaskHostNodeKey(HandshakeOptions.TaskHost | HandshakeOptions.NET, 1); | ||
| var key2 = new TaskHostNodeKey(HandshakeOptions.TaskHost | HandshakeOptions.X64, 2); | ||
|
|
||
| dict[key1] = "value1"; | ||
| dict[key2] = "value2"; | ||
|
|
||
| dict[key1].ShouldBe("value1"); | ||
| dict[key2].ShouldBe("value2"); | ||
|
|
||
| // Create a new key with same values as key1 | ||
| var key1Copy = new TaskHostNodeKey(HandshakeOptions.TaskHost | HandshakeOptions.NET, 1); | ||
| dict[key1Copy].ShouldBe("value1"); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void TaskHostNodeKey_LargeNodeId_Works() | ||
| { | ||
| // Test that we can use node IDs greater than 255 (the previous limit) | ||
| var key1 = new TaskHostNodeKey(HandshakeOptions.TaskHost | HandshakeOptions.NET, 256); | ||
| var key2 = new TaskHostNodeKey(HandshakeOptions.TaskHost | HandshakeOptions.NET, 1000); | ||
| var key3 = new TaskHostNodeKey(HandshakeOptions.TaskHost | HandshakeOptions.NET, int.MaxValue); | ||
|
|
||
| key1.NodeId.ShouldBe(256); | ||
| key2.NodeId.ShouldBe(1000); | ||
| key3.NodeId.ShouldBe(int.MaxValue); | ||
|
|
||
| // Ensure they are all different | ||
| key1.ShouldNotBe(key2); | ||
| key2.ShouldNotBe(key3); | ||
| key1.ShouldNotBe(key3); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void TaskHostNodeKey_NegativeNodeId_Works() | ||
| { | ||
| // Traditional multi-proc builds use -1 for node ID | ||
| var key = new TaskHostNodeKey(HandshakeOptions.TaskHost | HandshakeOptions.NET, -1); | ||
|
|
||
| key.NodeId.ShouldBe(-1); | ||
| key.HandshakeOptions.ShouldBe(HandshakeOptions.TaskHost | HandshakeOptions.NET); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void TaskHostNodeKey_AllHandshakeOptions_Work() | ||
| { | ||
| // Test various HandshakeOptions combinations | ||
| HandshakeOptions[] optionsList = | ||
| [ | ||
| HandshakeOptions.None, | ||
| HandshakeOptions.TaskHost, | ||
| HandshakeOptions.TaskHost | HandshakeOptions.NET, | ||
| HandshakeOptions.TaskHost | HandshakeOptions.X64, | ||
| HandshakeOptions.TaskHost | HandshakeOptions.NET | HandshakeOptions.NodeReuse, | ||
| HandshakeOptions.TaskHost | HandshakeOptions.CLR2, | ||
| HandshakeOptions.TaskHost | HandshakeOptions.Arm64 | ||
| ]; | ||
|
|
||
| foreach (var options in optionsList) | ||
| { | ||
| var key = new TaskHostNodeKey(options, 42); | ||
|
|
||
| key.HandshakeOptions.ShouldBe(options); | ||
| key.NodeId.ShouldBe(42); | ||
| } | ||
| } | ||
| } | ||
| } |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this method needed for anything now? if no, remove
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
SendData(int nodeId, INodePacket packet)method is required by theINodeProviderinterface but not actually used for task hosts (task hosts useSendData(TaskHostNodeKey, ...)viaTaskHostTask). Similar toTaskHostNodeManager.SendData, keeping it asNotImplementedExceptionto satisfy the interface contract.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a bit sus, but I suppose it works, flagging this for reviewers