Skip to content

Conversation

@mikhailshilkov
Copy link
Member

Adds a follow-up test to #1678 that has a component with multiple styles of async operations

@mikhailshilkov mikhailshilkov added the impact/no-changelog-required This issue doesn't require a CHANGELOG update label Mar 10, 2025
@mikhailshilkov mikhailshilkov requested a review from a team as a code owner March 10, 2025 09:37
try {
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://jsonplaceholder.typicode.com/todos/" + todoId))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does Java have something like Go's test HTTP server? Or is there another way to simulate this asyncronicity? It's not ideal to make an actual HTTP request in our tests, especially to a site we don't control.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could do a Java http server but I don't think I have the right lifecycle to start/stop it...

HttpServer server = HttpServer.create(new InetSocketAddress(8000), 0);
server.createContext("/test", exchange -> {
    String response = "{\"status\":\"ok\"}";
    exchange.sendResponseHeaders(200, response.length());
    try (var os = exchange.getResponseBody()) {
        os.write(response.getBytes());
    }
});
server.start();

We could do something fake like

URI uri = URI.create("data:text/plain,Hello%20World");
HttpRequest request = HttpRequest.newBuilder().uri(uri).build();

but I'm not sure it catches all the right problems?

The TODO thing is specifically designed for this case: "Free fake and reliable API for testing and prototyping". I think we are relatively safe and get a real test with some networking and latency, which may affect the asynchronous behavior?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we are relatively safe and get a real test with some networking and latency

Every network call in the tests are a potential source for flakes/CI breakages, so I'd really rather not introduce the dependency. Even the most stable services tend to break sometimes, in which case CI is gonna be red.

@mikhailshilkov mikhailshilkov force-pushed the mikhailshilkov/async-component-test branch from 447bfa8 to 356007e Compare March 10, 2025 10:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

impact/no-changelog-required This issue doesn't require a CHANGELOG update

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants