Skip to content
Open
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
35 changes: 30 additions & 5 deletions DevProxy.Integration.Tests/ProcessSmokeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public async Task Startup_EnvironmentOverrides_PreserveTildeConfigPathAndApplyBe
{
File.Delete(logFile);
}
workDir.Delete(recursive: true);
DeleteWorkDir(workDir);
}
}
}
Expand Down Expand Up @@ -302,7 +302,7 @@ public async Task Status_HonorsInstanceTokenSuppression_ExplicitRetrievalRemains
{
File.Delete(logFile);
}
workDir.Delete(recursive: true);
DeleteWorkDir(workDir);
}
}
}
Expand Down Expand Up @@ -521,7 +521,7 @@ public async Task Host_LoadsMockPluginFromConfig_AndServesMock()
}
finally
{
workDir.Delete(recursive: true);
DeleteWorkDir(workDir);
// The host writes a timestamped log to the working dir's parent in some modes;
// the temp dir delete above covers logs written under workDir. Best-effort.
}
Expand Down Expand Up @@ -591,7 +591,7 @@ await process.StandardInput.WriteAsync(
}
finally
{
workDir.Delete(recursive: true);
DeleteWorkDir(workDir);
}
}

Expand Down Expand Up @@ -650,7 +650,7 @@ await File.WriteAllTextAsync(Path.Combine(workDir.FullName, "devproxyrc.json"),
}
finally
{
workDir.Delete(recursive: true);
DeleteWorkDir(workDir);
}
}

Expand Down Expand Up @@ -735,6 +735,31 @@ private static async Task<int> WaitForListeningPortAsync(Process process)
}
}

// On Windows, a killed process can keep its working directory in use for a moment after
// Kill returns, and descendants such as the stdio child can't be waited for.
private static void DeleteWorkDir(DirectoryInfo workDir)
{
var deadline = DateTime.UtcNow.AddSeconds(10);
while (true)
{
workDir.Refresh();
if (!workDir.Exists)
{
return;
}

try
{
workDir.Delete(recursive: true);
return;
}
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException && DateTime.UtcNow < deadline)
{
Thread.Sleep(200);
}
}
}

private static void StopHost(Process process)
{
try
Expand Down
Loading