-
Notifications
You must be signed in to change notification settings - Fork 649
Fix thread safety issue in FindAppHostProjectFilesAsync by switching to ConcurrentBag #9655
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
Changes from 2 commits
5676167
e53bba6
2e45f79
e284fcd
9c8bc8c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -117,12 +117,25 @@ public async Task UseOrFindAppHostProjectFilePromptsWhenMultipleFilesFound() | |
var projectFile2 = new FileInfo(Path.Combine(workspace.WorkspaceRoot.FullName, "AppHost2.csproj")); | ||
await File.WriteAllTextAsync(projectFile2.FullName, "Not a real project file."); | ||
|
||
// Verify both files were created | ||
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. Drop the changes in this file. 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. Reverted all changes to the test file as requested. e284fcd |
||
Assert.True(projectFile1.Exists, $"Project file 1 should exist: {projectFile1.FullName}"); | ||
Assert.True(projectFile2.Exists, $"Project file 2 should exist: {projectFile2.FullName}"); | ||
|
||
// Verify string comparison works as expected | ||
var comparison = projectFile1.FullName.CompareTo(projectFile2.FullName); | ||
radical marked this conversation as resolved.
Show resolved
Hide resolved
|
||
outputHelper.WriteLine($"File comparison result: {comparison}"); | ||
outputHelper.WriteLine($"File 1: {projectFile1.FullName}"); | ||
outputHelper.WriteLine($"File 2: {projectFile2.FullName}"); | ||
|
||
Assert.True(comparison < 0, "AppHost1.csproj should come before AppHost2.csproj alphabetically"); | ||
radical marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
var runner = new TestDotNetCliRunner(); | ||
var interactionService = new TestInteractionService(); | ||
var projectLocator = new ProjectLocator(logger, runner, workspace.WorkspaceRoot, interactionService); | ||
|
||
var selectedProjectFile = await projectLocator.UseOrFindAppHostProjectFileAsync(null); | ||
|
||
outputHelper.WriteLine($"Selected: {selectedProjectFile?.FullName}"); | ||
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. Drop this as the filename would be shown if the following Assert fails. 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. Removed the debugging output line as requested. 2e45f79 |
||
Assert.Equal(projectFile1.FullName, selectedProjectFile!.FullName); | ||
} | ||
|
||
|
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.
@copilot Change this back to List and instead of using ConcurrentBag synchronize access to the list inside the callback to Parallel.ForEachAsync and lock the collection when adding items to it.
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.
Changed back to List with locking as requested. Removed ConcurrentBag import, added lock object, and wrapped the list.Add call in a lock statement for thread safety. 9c8bc8c