Skip to content

Commit de472b1

Browse files
Add health service integration test (#1793)
Co-authored-by: Brennan <[email protected]>
1 parent d975570 commit de472b1

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

test/FunctionalTests/Client/UnaryTests.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
using Greet;
2121
using Grpc.AspNetCore.FunctionalTests.Infrastructure;
2222
using Grpc.Core;
23+
using Grpc.Health.V1;
2324
using Grpc.Net.Client;
2425
using Grpc.Tests.Shared;
2526
using Microsoft.Extensions.Logging;
@@ -166,5 +167,17 @@ async Task<HelloReply> UnaryThrowError(HelloRequest request, ServerCallContext c
166167
}
167168
#endif
168169

170+
[Test]
171+
public async Task Health_Check_Success()
172+
{
173+
// Arrange
174+
var client = new Health.V1.Health.HealthClient(Channel);
175+
176+
// Act
177+
var result = await client.CheckAsync(new HealthCheckRequest());
178+
179+
// Assert
180+
Assert.AreEqual(HealthCheckResponse.Types.ServingStatus.Serving, result.Status);
181+
}
169182
}
170183
}

testassets/FunctionalTestsWebsite/FunctionalTestsWebsite.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@
1010
<ItemGroup>
1111
<ProjectReference Include="..\..\src\Grpc.AspNetCore.Web\Grpc.AspNetCore.Web.csproj" />
1212
<ProjectReference Include="..\..\src\Grpc.AspNetCore\Grpc.AspNetCore.csproj" />
13+
<ProjectReference Include="..\..\src\Grpc.HealthCheck\Grpc.HealthCheck.csproj" />
1314

1415
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="$(MicrosoftAspNetCoreApp31PackageVersion)" />
1516
<PackageReference Include="System.Net.Http.Json" Version="$(MicrosoftAspNetCoreAppPackageVersion)" />
16-
17+
1718
<Protobuf Include="..\Proto\any.proto" Link="Protos\any.proto" />
1819
<Protobuf Include="..\Proto\authorize.proto" Link="Protos\authorize.proto" />
1920
<Protobuf Include="..\Proto\chat.proto" Link="Protos\chat.proto" />

testassets/FunctionalTestsWebsite/Startup.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
using FunctionalTestsWebsite.Services;
2424
using Greet;
2525
using Grpc.AspNetCore.Server.Model;
26+
using Grpc.HealthCheck;
2627
using Grpc.Tests.Shared;
2728
using Microsoft.AspNetCore.Authentication.JwtBearer;
2829
using Microsoft.Extensions.DependencyInjection.Extensions;
@@ -104,6 +105,13 @@ public void ConfigureServices(IServiceCollection services)
104105
// Add a Singleton service
105106
services.AddSingleton<SingletonCounterService>();
106107

108+
services.AddSingleton<HealthServiceImpl>(s =>
109+
{
110+
var service = new HealthServiceImpl();
111+
service.SetStatus("", Grpc.Health.V1.HealthCheckResponse.Types.ServingStatus.Serving);
112+
return service;
113+
});
114+
107115
static Uri GetCurrentAddress(IServiceProvider serviceProvider)
108116
{
109117
// Get the address of the current server from the request
@@ -184,6 +192,7 @@ public void Configure(IApplicationBuilder app)
184192
endpoints.MapGrpcService<EchoService>();
185193
endpoints.MapGrpcService<IssueService>();
186194
endpoints.MapGrpcService<TesterService>();
195+
endpoints.MapGrpcService<HealthServiceImpl>();
187196

188197
endpoints.DataSources.Add(endpoints.ServiceProvider.GetRequiredService<DynamicEndpointDataSource>());
189198

0 commit comments

Comments
 (0)