bitflicker64 commented on code in PR #3185:
URL: https://github.com/apache/hugegraph/pull/3185#discussion_r3952111886


##########
hugegraph-server/hugegraph-dist/src/assembly/travis/test-start-hugegraph-pd.sh:
##########
@@ -111,6 +111,23 @@ wait_for_pd() {
     return 1
 }
 
+# Wait until PD readiness answers, or timeout. Same gate the docs recommend:
+# -f rejects the 503, the body match rejects a 200 that is an auth envelope 
rather
+# than a readiness answer. No credentials, and a single-node group elects 
itself.
+# Captured rather than piped: under pipefail a grep -q SIGPIPE could misread a
+# ready PD, and wait_for_pd() above uses the same shape.
+wait_for_pd_ready() {
+    local elapsed=0
+    while (( elapsed < STARTUP_WAIT )); do
+        local body
+        body=$(curl -fsS "$PD_URL/v1/ready" 2>/dev/null || true)
+        grep -q '"ready":true' <<<"$body" && return 0

Review Comment:
   Fixed in `8c6f0a363`. It now matches `"ready"[[:space:]]*:[[:space:]]*true` 
with `grep -Eq`, so compact, spaced and pretty-printed bodies all match while 
`"ready":false` still does not.



##########
hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/rest/RestApiTest.java:
##########
@@ -62,6 +62,56 @@ public void testQueryClusterInfo() throws 
URISyntaxException, IOException, Inter
         assert obj.getInt("status") == 0;
     }
 
+    @Test
+    public void testHealthNeedsNoAuth() throws URISyntaxException, IOException,
+                                             InterruptedException {
+        String url = pdRestAddr + "/v1/health";
+        HttpRequest request = HttpRequest.newBuilder().uri(new 
URI(url)).GET().build();
+        HttpResponse<String> response = client.send(request, 
HttpResponse.BodyHandlers.ofString());
+        assert response.statusCode() == 200;
+        // A 200 alone does not prove the path is anonymous: as of 1.7.0 the 
auth interceptor
+        // refuses with 200 and an error envelope. checkHealthy() returns an 
empty body, which
+        // separates the two whichever status a refusal carries.
+        assert response.body().isEmpty() : "expected an empty body, got " + 
response.body();
+    }
+
+    @Test
+    public void testReadyNeedsNoAuthAndReflectsRaft() throws 
URISyntaxException, IOException,
+                                                            
InterruptedException, JSONException {
+        // The CI PD is a single-node raft group, so it is its own leader and 
must be ready
+        String url = pdRestAddr + "/v1/ready";
+        HttpRequest request = HttpRequest.newBuilder().uri(new 
URI(url)).GET().build();
+        HttpResponse<String> response = client.send(request, 
HttpResponse.BodyHandlers.ofString());
+        assert response.statusCode() == 200 : "expected 200, got " + 
response.statusCode() +
+                                              " body=" + response.body();
+        JSONObject obj = new JSONObject(response.body());
+        assert obj.getBoolean("ready");
+        assert obj.getBoolean("isLeader");
+        assert "STATE_LEADER".equals(obj.getString("state"));
+        // Unauthenticated, so it must not disclose cluster addresses
+        assert !obj.has("leader") : "the anonymous body must not carry the 
leader address";
+    }

Review Comment:
   Added in `41318057b`. New `StoreAPIReadyTest` with three cases: raft not 
started (503, `state=STATE_UNINITIALIZED`), a follower that lost its leader 
(503, `STATE_FOLLOWER`), and a leader (200, `ready` and `isLeader` true) so an 
inverted ternary fails too. Each asserts the body keys, not just the status.
   
   Proved it catches the regression rather than assuming: forcing 
`HttpStatus.OK` makes two of the three fail, restoring makes them pass.
   
   It lives in `hg-pd-service`'s own test source set, since `hg-pd-service` is 
repackaged by `spring-boot-maven-plugin` and a test under `hg-pd-test` cannot 
resolve the service classes. It uses a `reflect.Proxy` `Node` that throws on 
any call, so it also pins that the endpoint never touches the raft node. No 
mockito.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to