@@ -48,7 +48,7 @@ class Executor : ITestExecutor
48
48
private const int _timeoutMiliseconds = 1000 ;
49
49
50
50
/// test session timeout (from the runsettings file)
51
- private int _testSessionTimeout = 300000 ;
51
+ private int _testSessionTimeout = 30_0000 ;
52
52
53
53
private IFrameworkHandle _frameworkHandle = null ;
54
54
@@ -552,27 +552,36 @@ await Task.Run(async delegate
552
552
}
553
553
554
554
StringBuilder output = new StringBuilder ( ) ;
555
- bool isFinished = false ;
555
+ ManualResetEvent testExecutionCompleted = new ManualResetEvent ( false ) ;
556
+
556
557
// attach listener for messages
557
558
device . DebugEngine . OnMessage += ( message , text ) =>
558
559
{
559
560
_logger . LogMessage ( text , Settings . LoggingLevel . Verbose ) ;
560
561
output . Append ( text ) ;
561
562
if ( text . Contains ( Done ) )
562
563
{
563
- isFinished = true ;
564
+ // signal test execution completed
565
+ testExecutionCompleted . Set ( ) ;
564
566
}
565
567
} ;
566
568
567
569
device . DebugEngine . RebootDevice ( RebootOptions . ClrOnly ) ;
568
570
569
- while ( ! isFinished )
571
+ DateTime timeoutForExecution = DateTime . UtcNow . AddMilliseconds ( _testSessionTimeout ) ;
572
+
573
+ if ( testExecutionCompleted . WaitOne ( _testSessionTimeout ) )
570
574
{
571
- Thread . Sleep ( 1 ) ;
572
- }
575
+ _logger . LogMessage ( $ "Tests finished.", Settings . LoggingLevel . Verbose ) ;
573
576
574
- _logger . LogMessage ( $ "Tests finished.", Settings . LoggingLevel . Verbose ) ;
575
- ParseTestResults ( output . ToString ( ) , results ) ;
577
+ ParseTestResults ( output . ToString ( ) , results ) ;
578
+ }
579
+ else
580
+ {
581
+ _logger . LogMessage ( $ "Tests timed out.", Settings . LoggingLevel . Error ) ;
582
+ results . First ( ) . Outcome = TestOutcome . Failed ;
583
+ results . First ( ) . ErrorMessage = $ "Tests timed out in { device . Description } ";
584
+ }
576
585
}
577
586
else
578
587
{
@@ -673,8 +682,8 @@ private async Task<List<TestResult>> RunTestOnEmulatorAsync(
673
682
. WithArguments ( arguments . ToString ( ) )
674
683
. WithValidation ( CommandResultValidation . None ) ;
675
684
676
- // setup cancellation token with a timeout of 5 seconds
677
- using ( var cts = new CancellationTokenSource ( TimeSpan . FromSeconds ( 5 ) ) )
685
+ // setup cancellation token with the timeout from settings
686
+ using ( var cts = new CancellationTokenSource ( _testSessionTimeout ) )
678
687
{
679
688
var cliResult = await cmd . ExecuteBufferedAsync ( cts . Token ) ;
680
689
var exitCode = cliResult . ExitCode ;
0 commit comments