in src/cs/PhoneticMatchingPerfTests/FuzzyMatcherPerfTester.cs [25:69]
internal void Run(TimeSpan timeout, bool isAccuracyTest = false)
{
using (var tokenSource = new CancellationTokenSource())
{
var ct = tokenSource.Token;
Stopwatch testStopwatch = new Stopwatch();
Action testTaskAction;
if (isAccuracyTest)
{
testTaskAction = () => this.AccuracyTest(ct, testStopwatch, false);
}
else
{
testTaskAction = () => this.AccuracyTest(ct, testStopwatch, true);
}
Console.WriteLine($"Running test loop for {timeout}...");
var task = Task.Factory.StartNew(testTaskAction, ct);
try
{
testStopwatch.Start();
tokenSource.CancelAfter(timeout);
bool taskCompleted = task.Wait(timeout + TimeSpan.FromMilliseconds(1000));
if (!taskCompleted)
{
throw new Exception("Error! Test task wasn't cancelled as expected. A single test should not block for more than 1 second.");
}
}
catch (AggregateException ex)
{
foreach (var inner in ex.InnerExceptions)
{
Console.WriteLine(inner.Message);
}
}
finally
{
Console.WriteLine($"Test completed!");
this.WriteStats(testStopwatch);
}
}
}