-
Notifications
You must be signed in to change notification settings - Fork 339
Fix CPU is consumed by polling frequently when there is no subscriber #4735
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
cvpoienaru
merged 12 commits into
microsoft:main
from
nohwnd:Fix-tight-loop-when-waiting
Nov 14, 2023
Merged
Changes from 3 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
49aac93
Try
nohwnd 41ebb08
Fix polling issue
nohwnd d1ab2af
revert playground
nohwnd af6073e
Apply wait.
nohwnd 15f98a5
Fixed test build
cvpoienaru b105153
Re-enabled testhost prestart
cvpoienaru 6a2d61d
Fixed test
cvpoienaru 1cb8a6e
Update src/Microsoft.TestPlatform.CommunicationUtilities/Interfaces/C…
cvpoienaru e823a60
Fixed unit tests
cvpoienaru 0f76419
Merge branch 'Fix-tight-loop-when-waiting' of https://github.com/nohw…
cvpoienaru 5d13418
Fixed build error
cvpoienaru b483355
Fixed unit tests
cvpoienaru 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
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 |
|---|---|---|
|
|
@@ -4,12 +4,12 @@ | |
| using System; | ||
| using System.IO; | ||
| using System.Text; | ||
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
|
|
||
| using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.Interfaces; | ||
| using Microsoft.VisualStudio.TestPlatform.ObjectModel; | ||
| using Microsoft.VisualStudio.TestPlatform.PlatformAbstractions; | ||
| using Microsoft.VisualStudio.TestPlatform.Utilities; | ||
|
|
||
| namespace Microsoft.VisualStudio.TestPlatform.CommunicationUtilities; | ||
|
|
||
|
|
@@ -37,7 +37,7 @@ public LengthPrefixCommunicationChannel(Stream stream) | |
| } | ||
|
|
||
| /// <inheritdoc /> | ||
| public event EventHandler<MessageReceivedEventArgs>? MessageReceived; | ||
| public TrackableEvent<MessageReceivedEventArgs> MessageReceived { get; } = new TrackableEvent<MessageReceivedEventArgs>(); | ||
|
|
||
| /// <inheritdoc /> | ||
| public Task Send(string data) | ||
|
|
@@ -71,7 +71,7 @@ public Task Send(string data) | |
| } | ||
|
|
||
| /// <inheritdoc /> | ||
| public Task NotifyDataAvailable() | ||
| public Task NotifyDataAvailable(CancellationToken cancellationToken) | ||
| { | ||
| try | ||
| { | ||
|
|
@@ -85,14 +85,10 @@ public Task NotifyDataAvailable() | |
| // Try read data even if no one is listening to the data stream. Some server | ||
| // implementations (like Sockets) depend on the read operation to determine if a | ||
| // connection is closed. | ||
nohwnd marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if (MessageReceived != null) | ||
| if (MessageReceived.WaitForSubscriber(1000, cancellationToken)) | ||
| { | ||
| var data = _reader.ReadString(); | ||
| MessageReceived.SafeInvoke(this, new MessageReceivedEventArgs { Data = data }, "LengthPrefixCommunicationChannel: MessageReceived"); | ||
| } | ||
| else | ||
| { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This message is unnecessary, and way too much detail. with prestart it is normal that client is waiting for his turn and this would just add yet another message to the log that would always repeat. |
||
| EqtTrace.Verbose("LengthPrefixCommunicationChannel.NotifyDataAvailable: New data are waiting to be received, but there is no subscriber to be notified. Not reading them from the stream."); | ||
| MessageReceived.Notify(this, new MessageReceivedEventArgs { Data = data }, "LengthPrefixCommunicationChannel: MessageReceived"); | ||
| } | ||
| } | ||
| catch (ObjectDisposedException ex) when (!_reader.BaseStream.CanRead) | ||
|
|
||
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
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
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.