Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public enum ExitCode { Success = 0, StressError = 1, CliError = 2 };

public static readonly bool IsQuicSupported = QuicListener.IsSupported && QuicConnection.IsSupported;

private static readonly Dictionary<string, int> s_unobservedExceptions = new Dictionary<string, int>();

public static async Task<int> Main(string[] args)
{
if (!TryParseCli(args, out Configuration? config))
Expand Down Expand Up @@ -186,6 +188,18 @@ private static async Task<ExitCode> Run(Configuration config)
Console.WriteLine("Query Parameters: " + config.MaxParameters);
Console.WriteLine();

if (config.RunMode.HasFlag(RunMode.client))
{
TaskScheduler.UnobservedTaskException += (_, e) =>
{
lock (s_unobservedExceptions)
{
string text = e.Exception.ToString();
s_unobservedExceptions[text] = s_unobservedExceptions.GetValueOrDefault(text) + 1;
}
};
}

StressServer? server = null;
if (config.RunMode.HasFlag(RunMode.server))
{
Expand All @@ -210,8 +224,10 @@ private static async Task<ExitCode> Run(Configuration config)
client?.Stop();
client?.PrintFinalReport();

Console.WriteLine($"Unobserved exceptions of {s_unobservedExceptions.Count} different types: {Environment.NewLine}{string.Join(Environment.NewLine + new string('=', 120) + Environment.NewLine, s_unobservedExceptions.Select(pair => $"Count {pair.Value}: {pair.Key}"))}");

// return nonzero status code if there are stress errors
return client?.TotalErrorCount == 0 ? ExitCode.Success : ExitCode.StressError;
return client?.TotalErrorCount == 0 && s_unobservedExceptions.Count == 0 ? ExitCode.Success : ExitCode.StressError;
}

private static async Task WaitUntilMaxExecutionTimeElapsedOrKeyboardInterrupt(TimeSpan? maxExecutionTime = null)
Expand Down