Skip to content

[HealthEndpoint] Test cases for GraphQL and REST in Health Check Report #2662

@sezal98

Description

@sezal98

The testing for Health Endpoint is failing for GraphQL and Rest calls with the error One or more errors occurred. (No connection could be made because the target machine actively refused it. (localhost:5000). This is due to an in memory server running and not an http server for internal calls to work on http://localhost endpoint.
We need to modify the HttpUtilities to pass the HttpClient from the Startup.cs and use the client from the factory instead of creating new.

But if /health internally calls /api and /graphql, and you're using the same in-memory TestServer, you might hit issues like:

  • Loopbacks not working: Since the same server is handling the request and the internal call, it could cause reentrancy issues or socket errors.
  • Your test app is running in-memory (via TestServer or WebApplicationFactory), and not actually listening on a real network port.

Boot up your app in-memory for integration tests.
Run your app in-memory via test code, likely using WebApplicationFactory, TestServer, or similar.
That means: Your app should be bound to an external port like http://localhost:80
Instead of in-memory (via the HttpClient returned from factory.CreateClient())
You need to inject the HttpClient from the test context into your health check logic, so it uses the in-memory test server instead of trying to call a real external address.

Metadata

Metadata

Assignees

Type

No type

Projects

Status

Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions