Test improvements (#17428)
Retry adding package and print reason for failure
This commit is contained in:
parent
b24b92494a
commit
32a2cc5943
|
|
@ -200,44 +200,52 @@ namespace Microsoft.DotNet.OpenApi.Commands
|
||||||
var packageId = kvp.Key;
|
var packageId = kvp.Key;
|
||||||
var version = urlPackages != null && urlPackages.ContainsKey(packageId) ? urlPackages[packageId] : kvp.Value;
|
var version = urlPackages != null && urlPackages.ContainsKey(packageId) ? urlPackages[packageId] : kvp.Value;
|
||||||
|
|
||||||
var args = new[] {
|
await TryAddPackage(packageId, version, projectFile);
|
||||||
"add",
|
}
|
||||||
"package",
|
}
|
||||||
packageId,
|
|
||||||
"--version",
|
|
||||||
version,
|
|
||||||
"--no-restore"
|
|
||||||
};
|
|
||||||
|
|
||||||
var muxer = DotNetMuxer.MuxerPathOrDefault();
|
private async Task TryAddPackage(string packageId, string packageVersion, FileInfo projectFile)
|
||||||
if (string.IsNullOrEmpty(muxer))
|
{
|
||||||
{
|
var args = new[] {
|
||||||
throw new ArgumentException($"dotnet was not found on the path.");
|
"add",
|
||||||
}
|
"package",
|
||||||
|
packageId,
|
||||||
|
"--version",
|
||||||
|
packageVersion,
|
||||||
|
"--no-restore"
|
||||||
|
};
|
||||||
|
|
||||||
var startInfo = new ProcessStartInfo
|
var muxer = DotNetMuxer.MuxerPathOrDefault();
|
||||||
{
|
if (string.IsNullOrEmpty(muxer))
|
||||||
FileName = muxer,
|
{
|
||||||
Arguments = string.Join(" ", args),
|
throw new ArgumentException($"dotnet was not found on the path.");
|
||||||
WorkingDirectory = projectFile.Directory.FullName,
|
}
|
||||||
RedirectStandardError = true,
|
|
||||||
RedirectStandardOutput = true,
|
|
||||||
};
|
|
||||||
|
|
||||||
var process = Process.Start(startInfo);
|
var startInfo = new ProcessStartInfo
|
||||||
|
{
|
||||||
|
FileName = muxer,
|
||||||
|
Arguments = string.Join(" ", args),
|
||||||
|
WorkingDirectory = projectFile.Directory.FullName,
|
||||||
|
RedirectStandardError = true,
|
||||||
|
RedirectStandardOutput = true,
|
||||||
|
};
|
||||||
|
|
||||||
var timeout = 20;
|
using var process = Process.Start(startInfo);
|
||||||
if (!process.WaitForExit(timeout * 1000))
|
|
||||||
{
|
|
||||||
throw new ArgumentException($"Adding package `{packageId}` to `{projectFile.Directory}` took longer than {timeout} seconds.");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (process.ExitCode != 0)
|
var timeout = 20;
|
||||||
{
|
if (!process.WaitForExit(timeout * 1000))
|
||||||
Out.Write(process.StandardOutput.ReadToEnd());
|
{
|
||||||
Error.Write(process.StandardError.ReadToEnd());
|
throw new ArgumentException($"Adding package `{packageId}` to `{projectFile.Directory}` took longer than {timeout} seconds.");
|
||||||
throw new ArgumentException($"Could not add package `{packageId}` to `{projectFile.Directory}`");
|
}
|
||||||
}
|
|
||||||
|
if (process.ExitCode != 0)
|
||||||
|
{
|
||||||
|
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