Assignment9+10 multithreading#101
Assignment9+10 multithreading#101RyanHirte wants to merge 65 commits intoIntelliTect-Samples:Assignment9+10-Multithreadingfrom
Conversation
string hostNameOrAddress, CancellationToken cancellationToken = default)
async public Task<PingResult> RunAsync(
string hostNameOrAddress, CancellationToken cancellationToken = default)
implementations
My work on the assignment so far for 11/22
…n windows and linux
There was a problem hiding this comment.
Pull request overview
This pull request implements multithreading functionality for a PingProcess class, adding async/await patterns, Task-based asynchronous methods, and parallel execution capabilities. The implementation includes comprehensive test coverage with a fake implementation for testing purposes.
Key Changes:
- Implemented async variants of ping operations (
RunAsync,RunTaskAsync,RunLongRunningAsync) with cancellation token support - Added parallel ping execution for multiple hosts with thread-safe output aggregation
- Created comprehensive test suite with cross-platform support and a
FakePingProcessfor deterministic testing
Reviewed changes
Copilot reviewed 10 out of 13 changed files in this pull request and generated 13 comments.
Show a summary per file
| File | Description |
|---|---|
| Directory.Build.props | Changed LangVersion to "latest" and added ParallelizeTestCollections setting |
| Assignment/PingProcess.cs | New implementation with async methods, Task-based patterns, and parallel execution support |
| Assignment/Assignment/PingProcess.cs | Removed old incomplete implementation |
| Assignment.Tests/PingProcessTests.cs | Comprehensive test suite with async tests and cross-platform support |
| Assignment.Tests/FakePingProcess.cs | Fake implementation for testing without actual network calls |
| Assignment.Tests/StringExtensions.cs | Renamed method from IsLikeRegEx to IsLikeRegExPattern |
| Assignment.Tests/WildCardPattern.cs | Added pragma directives to suppress warnings |
| Assignment.Tests/Assignment.Tests.csproj | Added ParallelizeTestCollections setting |
| Assignment.Tests/AssemblyAttributes.cs | Added assembly-level test parallelization configuration |
| Assignment/Assignment.Tests/PingProcessTests.cs | Removed old test file (relocated) |
| Assignment/.gitignore | Removed (likely consolidated to root level) |
| Assignment.sln | Whitespace/formatting changes only |
| Assignment/Assignment.csproj | Whitespace/formatting changes only |
Comments suppressed due to low confidence (9)
Directory.Build.props:5
- [nitpick] Changing
LangVersionfrom a specific version (13.0) tolatestcan introduce breaking changes or unexpected behavior when the SDK is updated. Thelatestkeyword means "the latest language version supported by this compiler," which could change without updating project files.
Consider using latestMajor instead, which provides new language features within the current major version without breaking changes, or stick to an explicit version number for more predictable builds.
Assignment/PingProcess.cs:132
- Disposable 'ManualResetEventSlim' is created but not disposed.
process.StartInfo.RedirectStandardOutput ? new(initialState: false) : null;
Assignment/PingProcess.cs:134
- Disposable 'ManualResetEventSlim' is created but not disposed.
process.StartInfo.RedirectStandardError ? new(initialState: false) : null;
Assignment.Tests/WildCardPattern.cs:152
- These 'if' statements can be combined.
Assignment.Tests/WildCardPattern.cs:362 - These 'if' statements can be combined.
Assignment.Tests/WildCardPattern.cs:622 - These 'if' statements can be combined.
Assignment.Tests/WildCardPattern.cs:255 - Both branches of this 'if' statement return - consider using '?' to express intent better.
Assignment.Tests/WildCardPattern.cs:383 - Both branches of this 'if' statement return - consider using '?' to express intent better.
Assignment.Tests/WildCardPattern.cs:1177 - Both branches of this 'if' statement write to the same variable - consider using '?' to express intent better.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
BillMillerCoding
left a comment
There was a problem hiding this comment.
Implement PingProcess' public Task RunTaskAsync(string hostNameOrAddress) ✔
First implement public void RunTaskAsync_Success() test method to test PingProcess.RunTaskAsync() using "localhost". ✔
Do NOT use async/await in this implementation. ✔
Implement PingProcess' async public Task RunAsync(string hostNameOrAddress) ✔
First implement the public void RunAsync_UsingTaskReturn_Success() test method to test PingProcess.RunAsync() using "localhost" without using async/await. ✔
Also implement the async public Task RunAsync_UsingTpl_Success() test method to test PingProcess.RunAsync() using "localhost" but this time DO using async/await. ✔
Add support for an optional cancellation token to the PingProcess.RunAsync() signature. ✔ Inside the PingProcess.RunAsync() invoke the token's ThrowIfCancellationRequested() method so an exception is thrown. ✔ Test that, when cancelled from the test method, the exception thrown is an AggregateException ✔ with a TaskCanceledException inner exception ✔ using the test methods RunAsync_UsingTplWithCancellation_CatchAggregateExceptionWrapping ✔and RunAsync_UsingTplWithCancellation_CatchAggregateExceptionWrappingTaskCanceledException ✔ respectively.
Complete/fix AND test async public Task RunAsync(IEnumerable hostNameOrAddresses, CancellationToken cancellationToken = default) which executes ping for an array of hostNameOrAddresses (which can all be "localhost") in parallel, adding synchronization if needed. ✔ NOTE:
The order of the items in the stdOutput is irrelevant and expected to be intermingled.
StdOutput must have all the ping output returned (no lines can be missing) even though intermingled. ✔
Implement AND test public Task RunLongRunningAsync(ProcessStartInfo startInfo, Action<string?>? progressOutput, Action<string?>? progressError, CancellationToken token) using Task.Factory.StartNew() and invoking RunProcessInternal with a TaskCreation value of TaskCreationOptions.LongRunning and a TaskScheduler value of TaskScheduler.Current. Returning a Task is also okay. NOTE: This method does NOT use Task.Run. ✔
lace all shared project properties into a Directory.Build.Props file.
Place all shared project items into a Directory.Build.targets file.
Ensure nullable reference types is enabled ✔
Ensure that you turn on code analysis for all projects(EnableNETAnalyzers) ✔
Set LangVersion and the TargetFramework to the latest released versions available (preview versions optional) ✔
and enabled .NET analyzers for both projects ✔
For this assignment, consider using Assert.AreEqual() (the generic version) ✔
All of the above should be unit tested ✔
Choose simplicity over complexity ✔
Looks good, most of the stuff I would have thought to point out, Copilot pointed out
steeley21
left a comment
There was a problem hiding this comment.
Good work! You've misnamed/ are missing some of the requirements with the testing, however. Once you get those added I think you'll be in good shape.
Instructions
- Implement PingProcess' public Task RunTaskAsync(string hostNameOrAddress) ✔
First implement public void RunTaskAsync_Success() test method to test PingProcess.RunTaskAsync() using "localhost". ❌
Do NOT use async/await in this implementation. ❌ - Implement PingProcess' async public Task RunAsync(string hostNameOrAddress) ✔
First implement the public void RunAsync_UsingTaskReturn_Success() test method to test PingProcess.RunAsync() using "localhost" without using async/await. ❌
Also implement the async public Task RunAsync_UsingTpl_Success() test method to test PingProcess.RunAsync() using "localhost" but this time DO using async/await. ❌ - Add support for an optional cancellation token to the PingProcess.RunAsync() signature. ✔ Inside the PingProcess.RunAsync() invoke the token's ThrowIfCancellationRequested() method so an exception is thrown. ✔ Test that, when cancelled from the test method, the exception thrown is an AggregateException ❌ with a TaskCanceledException inner exception ❌ using the test methods RunAsync_UsingTplWithCancellation_CatchAggregateExceptionWrapping ❌and RunAsync_UsingTplWithCancellation_CatchAggregateExceptionWrappingTaskCanceledException ❌ respectively.
- Complete/fix AND test async public Task RunAsync(IEnumerable hostNameOrAddresses, CancellationToken cancellationToken = default) which executes ping for an array of hostNameOrAddresses (which can all be "localhost") in parallel, adding synchronization if needed. ✔ NOTE:
The order of the items in the stdOutput is irrelevant and expected to be intermingled.
StdOutput must have all the ping output returned (no lines can be missing) even though intermingled. ✔ - Implement AND test public Task RunLongRunningAsync(ProcessStartInfo startInfo, Action<string?>? progressOutput, Action<string?>? progressError, CancellationToken token) using Task.Factory.StartNew() and invoking RunProcessInternal with a TaskCreation value of TaskCreationOptions.LongRunning and a TaskScheduler value of TaskScheduler.Current. Returning a Task is also okay. NOTE: This method does NOT use Task.Run.✔
Extra Credit
Test and implement PingProcess.RunAsync(System.IProgress progess) so that you can capture the output as it occurs rather than capturing the output only when the process finishes. ✔
Fundamentals
Place all shared project properties into a Directory.Build.Props file.
Place all shared project items into a Directory.Build.targets file.
Ensure nullable reference types is enabled ✔
Ensure that you turn on code analysis for all projects(EnableNETAnalyzers) ✔
Set LangVersion and the TargetFramework to the latest released versions available (preview versions optional) ✔
and enabled .NET analyzers for both projects ✔
For this assignment, consider using Assert.AreEqual() (the generic version) ✔
All of the above should be unit tested ✔
Choose simplicity over complexity ✔
9+10 test fixes
dispose of calcellation token source with a `using` statement
9+10 test fixes
Fixed review comment with stringbuilder
Added missing tests
SummarySummary
CoverageAssignment - 47%
|
Joshua-Lester3
left a comment
There was a problem hiding this comment.
Instructions
- Implement
PingProcess'public Task<PingResult> RunTaskAsync(string hostNameOrAddress)✔- First implement
public void RunTaskAsync_Success()test method to testPingProcess.RunTaskAsync()using"localhost". ✔ - Do NOT use async/await in this implementation. ✔
- First implement
- Implement
PingProcess'async public Task<PingResult> RunAsync(string hostNameOrAddress)✔- First implement the
public void RunAsync_UsingTaskReturn_Success()test method to testPingProcess.RunAsync()using"localhost"without using async/await. ✔ - Also implement the
async public Task RunAsync_UsingTpl_Success()test method to testPingProcess.RunAsync()using"localhost"but this time DO using async/await. ✔
- First implement the
- Add support for an optional cancellation token to the
PingProcess.RunAsync()signature. ✔
Inside thePingProcess.RunAsync()invoke the token'sThrowIfCancellationRequested()method so an exception is thrown. ✔
Test that, when cancelled from the test method, the exception thrown is anAggregateException✔ with aTaskCanceledExceptioninner exception ✔ using the test methodsRunAsync_UsingTplWithCancellation_CatchAggregateExceptionWrapping✔andRunAsync_UsingTplWithCancellation_CatchAggregateExceptionWrappingTaskCanceledException✔ respectively. - Complete/fix AND test
async public Task<PingResult> RunAsync(IEnumerable<string> hostNameOrAddresses, CancellationToken cancellationToken = default)which executes ping for an array of hostNameOrAddresses (which can all be "localhost") in parallel, adding synchronization if needed. ✔
NOTE:- The order of the items in the stdOutput is irrelevant and expected to be intermingled.
- StdOutput must have all the ping output returned (no lines can be missing) even though intermingled. ✔
- Implement AND test
public Task<int> RunLongRunningAsync(ProcessStartInfo startInfo, Action<string?>? progressOutput, Action<string?>? progressError, CancellationToken token)usingTask.Factory.StartNew()and invokingRunProcessInternalwith aTaskCreationvalue ofTaskCreationOptions.LongRunningand aTaskSchedulervalue ofTaskScheduler.Current. Returning aTask<PingResult>is also okay. ❌ Didn't use TaskScheduler.Current.
NOTE: This method does NOT useTask.Run.
Extra Credit
- Test and implement
PingProcess.RunAsync(System.IProgress<T> progess)so that you can capture the output as it occurs rather than capturing the output only when the process finishes. ✔
Fundamentals
- Place all shared project properties into a
Directory.Build.Propsfile. - Place all shared project items into a
Directory.Build.targetsfile. - Ensure nullable reference types is enabled ✔
- Ensure that you turn on code analysis for all projects(EnableNETAnalyzers) ✔
- Set
LangVersionand theTargetFrameworkto the latest released versions available (preview versions optional) ✔ - and enabled .NET analyzers for both projects ✔
- For this assignment, consider using
Assert.AreEqual<T>()(the generic version) ✔ - All of the above should be unit tested ✔
- Choose simplicity over complexity ✔
| }, | ||
| token, | ||
| TaskCreationOptions.LongRunning, | ||
| TaskScheduler.Default); |
There was a problem hiding this comment.
TaskScheduler.Current is what is required.
Worked on with @ColtonKnopik
Extra credit implemented