Skip to content
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

Add small delay to test file utilities to prevent race condition with Kestrel #586

Merged
merged 1 commit into from
Dec 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Testing/Acceptance/Utilities/FileUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,16 @@ public static void WriteText(string path, string content)

public static async ValueTask WriteTextAsync(string path, string content)
{
// Kestrel flushes its output buffers as soon as the content length sent in
// the headers is reached, causing the test execution to continue and introducing
// a race condition where the test writes again to the same file that is not
// yet disposed by the server. As there is no way around this, we will be hacky here.
await Task.Delay(100);

await using var file = File.Create(path, 4096, FileOptions.WriteThrough);

await file.WriteAsync(Encoding.UTF8.GetBytes(content));
await file.FlushAsync();
}

}
Loading