-
-
Notifications
You must be signed in to change notification settings - Fork 932
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove enormous array allocations in tests causing instability in CI #1367
Conversation
I have opened a ticket for lack of ideas https://help.appveyor.com/discussions/problems/35588-net-tests-silently-exiting-on-ubuntu2204 |
string token = ""; // https://ci.appveyor.com/api-keys
var client = new HttpClient();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
JsonDocument x = JsonDocument.Parse(await client.GetStringAsync("https://ci.appveyor.com/api/projects/drieseng/ssh-net/history?recordsNumber=200"));
int buildCount = 0;
int badCount = 0;
foreach (JsonElement build in x.RootElement.GetProperty("builds").EnumerateArray())
{
buildCount++;
long buildId = build.GetProperty("buildId").GetInt64();
string status = build.GetProperty("status").GetString();
if (status != "success")
{
continue;
}
foreach (var job in JsonDocument.Parse(
await client.GetStringAsync($"https://ci.appveyor.com/api/projects/drieseng/ssh-net/builds/{buildId}"))
.RootElement.GetProperty("build").GetProperty("jobs").EnumerateArray())
{
string jobId = job.GetProperty("jobId").GetString();
int testsCount = job.GetProperty("testsCount").GetInt32();
if (testsCount < 1000)
{
badCount++;
Console.WriteLine($"Bad: {testsCount} tests in https://ci.appveyor.com/project/drieseng/ssh-net/builds/{buildId}");
Console.WriteLine(string.Join(Environment.NewLine,
ReadLines(await client.GetStreamAsync($"https://ci.appveyor.com/api/buildjobs/{jobId}/log"))
.TakeLast(5)));
Console.WriteLine();
Console.WriteLine();
}
}
}
Console.WriteLine($"{badCount} bad of {buildCount}");
static IEnumerable<string> ReadLines(Stream s)
{
using StreamReader sr = new(s);
string line;
while ((line = sr.ReadLine()) != null)
{
yield return line;
}
}
|
Memory explodes:
|
Found it 🙂 Line 38 in 70a0a08
SSH.NET/test/Renci.SshNet.Tests/Classes/ServiceFactoryTest_CreateShellStream_Success.cs Line 37 in 70a0a08
|
Some of which are causing giant array allocations unnecessarily. Should stabilise CI.
Since these changes, I have run the CI 13 times successfully without any silent crashes at the ~840 test mark (the latest build failed one of the usual integration tests afterwards). At a 21 / 100 prior occurrence rate, the chance of 13 passes would be (1 - 0.21) ^ 13 ~= 4.66%. So I think we can say that this is the fix and that the process was crashing due to out-of-memory from these randomly-sized array allocations. Still a bit of a mystery why the dotnet process was showing exit code 0 though |
No description provided.