Example #1
0
        internal static async Task <T> CalculateRunTime <T>(Func <Task <T> > testToRun, bool printResult, [CallerMemberName] string testName = "")
        {
            TestTimer timer = new TestTimer()
            {
                PrintResult = printResult
            };
            T result = await testToRun();

            timer.EndAndPrint(testName);

            return(result);
        }
Example #2
0
 internal static async Task ExecuteWithTimeout(TestTimer timer, int timeout, Func <Task <bool> > repeatedCode,
                                               TimeSpan?delay = null, [CallerMemberName] string testName = "")
 {
     while (true)
     {
         if (await repeatedCode())
         {
             timer.EndAndPrint(testName);
             break;
         }
         if (timer.TotalMilliSecondsUntilNow >= timeout)
         {
             Assert.True(false, $"{testName} timed out after {timeout} milliseconds");
             break;
         }
         if (delay.HasValue)
         {
             await Task.Delay(delay.Value);
         }
     }
 }