|
4 | 4 | import com.fasterxml.jackson.databind.ObjectMapper; |
5 | 5 | import io.github.easy4j.opencli.OpenCliProperties; |
6 | 6 | import io.github.easy4j.opencli.contract.ContractProbe; |
| 7 | +import io.github.easy4j.opencli.contract.LifecycleProbe; |
7 | 8 | import java.io.File; |
8 | 9 | import java.io.IOException; |
9 | 10 | import java.net.InetSocketAddress; |
10 | 11 | import java.nio.charset.StandardCharsets; |
| 12 | +import java.nio.file.Files; |
| 13 | +import java.nio.file.Path; |
11 | 14 | import java.util.Arrays; |
12 | 15 | import java.util.Base64; |
13 | 16 | import java.util.List; |
|
22 | 25 | import org.java_websocket.handshake.ClientHandshake; |
23 | 26 | import org.java_websocket.server.WebSocketServer; |
24 | 27 | import org.junit.jupiter.api.Test; |
| 28 | +import org.junit.jupiter.api.io.TempDir; |
25 | 29 |
|
26 | 30 | import static org.junit.jupiter.api.Assertions.assertEquals; |
27 | 31 | import static org.junit.jupiter.api.Assertions.assertFalse; |
@@ -89,6 +93,25 @@ void exchangesRegistrationAndCollectResultsAndReconnectsAfterRemoteClose() throw |
89 | 93 | } |
90 | 94 | } |
91 | 95 |
|
| 96 | + @Test |
| 97 | + void collectBeforeRegistrationAcknowledgementDoesNotStartChild(@TempDir Path temporary) throws Exception { |
| 98 | + Path marker = temporary.resolve("child-started"); |
| 99 | + try (LocalCenter center = new LocalCenter(); |
| 100 | + OpenCliWsReverseAgentClient agent = new OpenCliWsReverseAgentClient( |
| 101 | + probe(LifecycleProbe.class.getName()), center.agentProperties())) { |
| 102 | + agent.start(); |
| 103 | + WireMessage registration = center.receive("register"); |
| 104 | + registration.socket.send(MAPPER.createObjectNode() |
| 105 | + .put("type", "collect").put("request_id", "early").put("site", "write") |
| 106 | + .put("command", marker.toString()).toString()); |
| 107 | + JsonNode rejected = center.receive("result").body; |
| 108 | + assertEquals("early", rejected.path("request_id").asText()); |
| 109 | + assertFalse(Files.exists(marker), "an unregistered collect started a child"); |
| 110 | + assertFalse(rejected.path("success").asBoolean()); |
| 111 | + assertEquals("worker is not registered", rejected.path("error").asText()); |
| 112 | + } |
| 113 | + } |
| 114 | + |
92 | 115 | @Test |
93 | 116 | void retriesAfterHandshakeCloseAndReturnsChildFailureToCenter() throws Exception { |
94 | 117 | try (LocalCenter center = new LocalCenter(); |
|
0 commit comments