Skip to content

Commit

Permalink
Add small delay to test file utilities to prevent race condition with…
Browse files Browse the repository at this point in the history
… Kestrel
  • Loading branch information
Kaliumhexacyanoferrat committed Dec 11, 2024
1 parent 1469935 commit c474206
Showing 1 changed file with 7 additions and 0 deletions.
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();
}

}

0 comments on commit c474206

Please sign in to comment.