Test improvements (#17428)
Retry adding package and print reason for failure
This commit is contained in:
parent
b24b92494a
commit
32a2cc5943
|
|
@ -200,12 +200,18 @@ namespace Microsoft.DotNet.OpenApi.Commands
|
|||
var packageId = kvp.Key;
|
||||
var version = urlPackages != null && urlPackages.ContainsKey(packageId) ? urlPackages[packageId] : kvp.Value;
|
||||
|
||||
await TryAddPackage(packageId, version, projectFile);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task TryAddPackage(string packageId, string packageVersion, FileInfo projectFile)
|
||||
{
|
||||
var args = new[] {
|
||||
"add",
|
||||
"package",
|
||||
packageId,
|
||||
"--version",
|
||||
version,
|
||||
packageVersion,
|
||||
"--no-restore"
|
||||
};
|
||||
|
||||
|
|
@ -224,7 +230,7 @@ namespace Microsoft.DotNet.OpenApi.Commands
|
|||
RedirectStandardOutput = true,
|
||||
};
|
||||
|
||||
var process = Process.Start(startInfo);
|
||||
using var process = Process.Start(startInfo);
|
||||
|
||||
var timeout = 20;
|
||||
if (!process.WaitForExit(timeout * 1000))
|
||||
|
|
@ -234,10 +240,12 @@ namespace Microsoft.DotNet.OpenApi.Commands
|
|||
|
||||
if (process.ExitCode != 0)
|
||||
{
|
||||
Out.Write(process.StandardOutput.ReadToEnd());
|
||||
Error.Write(process.StandardError.ReadToEnd());
|
||||
throw new ArgumentException($"Could not add package `{packageId}` to `{projectFile.Directory}`");
|
||||
}
|
||||
var output = await process.StandardOutput.ReadToEndAsync();
|
||||
var error = await process.StandardError.ReadToEndAsync();
|
||||
await Out.WriteAsync(output);
|
||||
await Error.WriteAsync(error);
|
||||
|
||||
throw new ArgumentException($"Could not add package `{packageId}` to `{projectFile.Directory}` due to: `{error}`");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue