Add a test with a component with async context switching#1726
Add a test with a component with async context switching#1726mikhailshilkov wants to merge 1 commit intomainfrom
Conversation
tests/integration/provider-maven/src/main/java/com/pulumi/example/provider/SampleAsync.java
Outdated
Show resolved
Hide resolved
| try { | ||
| HttpClient client = HttpClient.newHttpClient(); | ||
| HttpRequest request = HttpRequest.newBuilder() | ||
| .uri(URI.create("https://jsonplaceholder.typicode.com/todos/" + todoId)) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
447bfa8 to
356007e
Compare
Adds a follow-up test to #1678 that has a component with multiple styles of async operations