@@ -30,6 +30,7 @@ public class InstanceManagerTests : IDisposable
30
30
private readonly TestEnvironmentEx _environment ;
31
31
private readonly ScriptWebHostEnvironment _scriptWebEnvironment ;
32
32
private readonly InstanceManager _instanceManager ;
33
+ private readonly Mock < IMeshServiceClient > _meshServiceClientMock ;
33
34
private readonly HttpClient _httpClient ;
34
35
private readonly LoggerFactory _loggerFactory = new LoggerFactory ( ) ;
35
36
private readonly TestOptionsFactory < ScriptApplicationHostOptions > _optionsFactory = new TestOptionsFactory < ScriptApplicationHostOptions > ( new ScriptApplicationHostOptions ( ) { ScriptPath = Path . GetTempPath ( ) } ) ;
@@ -43,8 +44,10 @@ public InstanceManagerTests()
43
44
44
45
_environment = new TestEnvironmentEx ( ) ;
45
46
_scriptWebEnvironment = new ScriptWebHostEnvironment ( _environment ) ;
47
+ _meshServiceClientMock = new Mock < IMeshServiceClient > ( MockBehavior . Strict ) ;
46
48
47
- _instanceManager = new InstanceManager ( _optionsFactory , _httpClient , _scriptWebEnvironment , _environment , _loggerFactory . CreateLogger < InstanceManager > ( ) , new TestMetricsLogger ( ) , null ) ;
49
+ _instanceManager = new InstanceManager ( _optionsFactory , _httpClient , _scriptWebEnvironment , _environment ,
50
+ _loggerFactory . CreateLogger < InstanceManager > ( ) , new TestMetricsLogger ( ) , _meshServiceClientMock . Object ) ;
48
51
49
52
InstanceManager . Reset ( ) ;
50
53
}
@@ -126,6 +129,10 @@ public async Task StartAssignment_Failure_ExitsPlaceholderMode()
126
129
} ,
127
130
IsWarmupRequest = false
128
131
} ;
132
+
133
+ _meshServiceClientMock . Setup ( c => c . NotifyHealthEvent ( ContainerHealthEventType . Fatal ,
134
+ It . Is < Type > ( t => t == typeof ( InstanceManager ) ) , "Assign failed" ) ) . Returns ( Task . CompletedTask ) ;
135
+
129
136
bool result = _instanceManager . StartAssignment ( context ) ;
130
137
Assert . True ( result ) ;
131
138
Assert . True ( _scriptWebEnvironment . InStandbyMode ) ;
@@ -135,6 +142,9 @@ public async Task StartAssignment_Failure_ExitsPlaceholderMode()
135
142
var error = _loggerProvider . GetAllLogMessages ( ) . First ( p => p . Level == LogLevel . Error ) ;
136
143
Assert . Equal ( "Assign failed" , error . FormattedMessage ) ;
137
144
Assert . Equal ( "Kaboom!" , error . Exception . Message ) ;
145
+
146
+ _meshServiceClientMock . Verify ( c => c . NotifyHealthEvent ( ContainerHealthEventType . Fatal ,
147
+ It . Is < Type > ( t => t == typeof ( InstanceManager ) ) , "Assign failed" ) , Times . Once ) ;
138
148
}
139
149
140
150
[ Fact ]
@@ -504,7 +514,7 @@ public async Task SpecializeMSISidecar_Succeeds()
504
514
MSIContext = new MSIContext ( )
505
515
} ;
506
516
507
- var instanceManager = GetInstanceManagerForMSISpecialization ( assignmentContext , HttpStatusCode . OK ) ;
517
+ var instanceManager = GetInstanceManagerForMSISpecialization ( assignmentContext , HttpStatusCode . OK , null ) ;
508
518
509
519
string error = await instanceManager . SpecializeMSISidecar ( assignmentContext ) ;
510
520
Assert . Null ( error ) ;
@@ -532,7 +542,7 @@ public async Task SpecializeMSISidecar_NoOp_ForWarmup_Request()
532
542
IsWarmupRequest = true
533
543
} ;
534
544
535
- var instanceManager = GetInstanceManagerForMSISpecialization ( assignmentContext , HttpStatusCode . OK ) ;
545
+ var instanceManager = GetInstanceManagerForMSISpecialization ( assignmentContext , HttpStatusCode . OK , null ) ;
536
546
537
547
string error = await instanceManager . SpecializeMSISidecar ( assignmentContext ) ;
538
548
Assert . Null ( error ) ;
@@ -558,7 +568,7 @@ public async Task SpecializeMSISidecar_Fails()
558
568
MSIContext = new MSIContext ( )
559
569
} ;
560
570
561
- var instanceManager = GetInstanceManagerForMSISpecialization ( assignmentContext , HttpStatusCode . BadRequest ) ;
571
+ var instanceManager = GetInstanceManagerForMSISpecialization ( assignmentContext , HttpStatusCode . BadRequest , null ) ;
562
572
563
573
string error = await instanceManager . SpecializeMSISidecar ( assignmentContext ) ;
564
574
Assert . NotNull ( error ) ;
@@ -588,7 +598,12 @@ public async Task DoesNotSpecializeMSISidecar_WhenMSIContextNull()
588
598
MSIContext = null
589
599
} ;
590
600
591
- var instanceManager = GetInstanceManagerForMSISpecialization ( assignmentContext , HttpStatusCode . BadRequest ) ;
601
+
602
+ var meshServiceClient = new Mock < IMeshServiceClient > ( MockBehavior . Strict ) ;
603
+ meshServiceClient . Setup ( c => c . NotifyHealthEvent ( ContainerHealthEventType . Fatal ,
604
+ It . Is < Type > ( t => t == typeof ( InstanceManager ) ) , "Could not specialize MSI sidecar" ) ) . Returns ( Task . CompletedTask ) ;
605
+
606
+ var instanceManager = GetInstanceManagerForMSISpecialization ( assignmentContext , HttpStatusCode . BadRequest , meshServiceClient . Object ) ;
592
607
593
608
string error = await instanceManager . SpecializeMSISidecar ( assignmentContext ) ;
594
609
Assert . Null ( error ) ;
@@ -597,6 +612,9 @@ public async Task DoesNotSpecializeMSISidecar_WhenMSIContextNull()
597
612
Assert . Collection ( logs ,
598
613
p => Assert . StartsWith ( "MSI enabled status: True" , p ) ,
599
614
p => Assert . StartsWith ( "Skipping specialization of MSI sidecar since MSIContext was absent" , p ) ) ;
615
+
616
+ meshServiceClient . Verify ( c => c . NotifyHealthEvent ( ContainerHealthEventType . Fatal ,
617
+ It . Is < Type > ( t => t == typeof ( InstanceManager ) ) , "Could not specialize MSI sidecar" ) , Times . Once ) ;
600
618
}
601
619
602
620
[ Fact ]
@@ -710,7 +728,8 @@ public async Task Does_Not_Mount_Invalid_BYOS_Accounts()
710
728
client => client . MountCifs ( It . IsAny < string > ( ) , It . IsAny < string > ( ) , It . Is < string > ( s => s != targetPath1 ) ) , Times . Never ( ) ) ;
711
729
}
712
730
713
- private InstanceManager GetInstanceManagerForMSISpecialization ( HostAssignmentContext hostAssignmentContext , HttpStatusCode httpStatusCode )
731
+ private InstanceManager GetInstanceManagerForMSISpecialization ( HostAssignmentContext hostAssignmentContext ,
732
+ HttpStatusCode httpStatusCode , IMeshServiceClient meshServiceClient )
714
733
{
715
734
var handlerMock = new Mock < HttpMessageHandler > ( MockBehavior . Strict ) ;
716
735
@@ -728,7 +747,7 @@ private InstanceManager GetInstanceManagerForMSISpecialization(HostAssignmentCon
728
747
InstanceManager . Reset ( ) ;
729
748
730
749
return new InstanceManager ( _optionsFactory , new HttpClient ( handlerMock . Object ) , _scriptWebEnvironment , _environment ,
731
- _loggerFactory . CreateLogger < InstanceManager > ( ) , new TestMetricsLogger ( ) , null ) ;
750
+ _loggerFactory . CreateLogger < InstanceManager > ( ) , new TestMetricsLogger ( ) , meshServiceClient ) ;
732
751
}
733
752
734
753
public void Dispose ( )
0 commit comments