From c474206ad6fd609474f1feea38a03513a871fca1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20N=C3=A4geli?= Date: Wed, 11 Dec 2024 13:30:09 +0100 Subject: [PATCH] Add small delay to test file utilities to prevent race condition with Kestrel --- Testing/Acceptance/Utilities/FileUtil.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Testing/Acceptance/Utilities/FileUtil.cs b/Testing/Acceptance/Utilities/FileUtil.cs index 3c19a633..af524936 100644 --- a/Testing/Acceptance/Utilities/FileUtil.cs +++ b/Testing/Acceptance/Utilities/FileUtil.cs @@ -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(); } + }