Skip to content

Commit

Permalink
THRIFT-5514 netstd test client slow in multithread mode
Browse files Browse the repository at this point in the history
Client: netstd
Patch: Jens Geyer
  • Loading branch information
Jens-G committed Feb 12, 2022
1 parent 52d263e commit d2c28b3
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions test/netstd/Client/TestClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -411,15 +411,28 @@ public static async Task<int> Execute(List<string> args)
return ErrorUnknown;
}

var tests = Enumerable.Range(0, param.numThreads).Select(_ => new ClientTest(param)).ToArray();

//issue tests on separate threads simultaneously
var nThreads = Math.Max(param.numThreads, 1);
Console.Write("Starting {0} test thread(s) ", nThreads);
var tasks = new Task[nThreads];
var start = DateTime.Now;
var tasks = tests.Select(test => test.Execute()).ToArray();
var retcode = 0;
for (var i = 0; i < tasks.Length; ++i)
{
Console.Write('.');
tasks[i] = Task.Run(async () =>
{
var test = new ClientTest(param);
await test.Execute();
lock (tasks)
retcode |= test.ReturnCode;
});
}
Console.WriteLine(" OK");
Task.WaitAll(tasks);
Console.WriteLine("Total time: " + (DateTime.Now - start));
Console.WriteLine();
return tests.Select(t => t.ReturnCode).Aggregate((r1, r2) => r1 | r2);
return retcode;
}
catch (Exception outerEx)
{
Expand Down Expand Up @@ -490,7 +503,7 @@ public static byte[] PrepareTestData(bool randomDist, BinaryTestSize testcase)
return retval;
}

private static CancellationToken MakeTimeoutToken(int msec = 5000)
private static CancellationToken MakeTimeoutToken(int msec = 15_000)
{
var token = new CancellationTokenSource(msec);
return token.Token;
Expand Down

0 comments on commit d2c28b3

Please sign in to comment.