1212using Microsoft . ML . TestFramework ;
1313using Microsoft . ML . TestFramework . Attributes ;
1414using Microsoft . ML . TestFrameworkCommon ;
15+ using Microsoft . ML . TestFrameworkCommon . Attributes ;
1516using Xunit ;
1617using Xunit . Abstractions ;
1718using static Microsoft . ML . DataOperationsCatalog ;
@@ -375,8 +376,6 @@ public void AutoFitWithPresplittedData()
375376 }
376377
377378 [ LightGBMFact ]
378- //Skipping test temporarily. This test will be re-enabled once the cause of failures has been determined
379- [ Trait ( "Category" , "SkipInCI" ) ]
380379 public void AutoFitMaxExperimentTimeTest ( )
381380 {
382381 // A single binary classification experiment takes less than 5 seconds.
@@ -398,8 +397,30 @@ public void AutoFitMaxExperimentTimeTest()
398397 // can increase the run time of unit tests, and may not produce multiple runs.
399398 if ( experiment . RunDetails . Select ( r => r . Exception == null ) . Count ( ) > 1 && experiment . RunDetails . Last ( ) . Exception != null )
400399 {
401- Assert . True ( experiment . RunDetails . Last ( ) . Exception . Message . Contains ( "Operation was canceled" ) ,
402- "Training process was not successfully canceled after maximum experiment time was reached." ) ;
400+ var expectedExceptionMessage = "Operation was canceled" ;
401+ var lastException = experiment . RunDetails . Last ( ) . Exception ;
402+ var containsMessage = lastException . Message . Contains ( expectedExceptionMessage ) ;
403+
404+ if ( lastException is AggregateException lastAggregateException )
405+ {
406+ // Sometimes multiple threads might throw the same "Operation was cancelled"
407+ // exception and all of them are grouped inside an AggregateException
408+ // Must check that all exceptions are the expected one.
409+ containsMessage = true ;
410+ foreach ( var ex in lastAggregateException . Flatten ( ) . InnerExceptions )
411+ {
412+ if ( ! ex . Message . Contains ( expectedExceptionMessage ) )
413+ {
414+ containsMessage = false ;
415+ }
416+ }
417+ }
418+
419+
420+ Assert . True ( containsMessage ,
421+ $ "Did not obtain '{ expectedExceptionMessage } ' error." +
422+ $ "Obtained unexpected error of type { lastException . GetType ( ) } with message: { lastException . Message } ") ;
423+
403424 // Ensure that the best found model can still run after maximum experiment time was reached.
404425 IDataView predictions = experiment . BestRun . Model . Transform ( trainData ) ;
405426 }
0 commit comments