Skip to content

Agent Mesh

e2e: idle nodes hold their router; a call connects them

Antonio Ojea975de2b48d03
diff --git a/tests/e2e/container_mesh.bats b/tests/e2e/container_mesh.bats
index 57ce98f9..8b9dcf68 100644
--- a/tests/e2e/container_mesh.bats
+++ b/tests/e2e/container_mesh.bats
@@ -40,9 +40,21 @@ teardown() {
[[ "$status" -eq 0 ]]
done
- # Verify connected peer count via MCP (wait for full mesh).
+ # An idle node holds its router and nothing else: members connect to one
+ # another when they call, not ahead of time.
for i in $(seq 1 "$node_count"); do
- run mesh_wait_for_node_count "${i}" $((node_count - 1)) 60
+ run mesh_wait_for_attached_routers "${i}" 1 30
+ [[ "$status" -eq 0 ]]
+ run mesh_wait_for_node_count "${i}" 0 5
[[ "$status" -eq 0 ]]
done
+
+ # Asked to, a node reaches another through the mesh.
+ local node2_peer_id
+ node2_peer_id="$(mesh_node_peer_id 2)"
+ [[ -n "${node2_peer_id}" ]]
+ run mesh_connect_peer 1 "$(mesh_node_addr 2)"
+ [[ "$status" -eq 0 ]]
+ run mesh_wait_for_peer_connection 1 "${node2_peer_id}" 30
+ [[ "$status" -eq 0 ]]
}
diff --git a/tests/e2e/lib/container_mesh.bash b/tests/e2e/lib/container_mesh.bash
index 8886c017..301d36be 100644
--- a/tests/e2e/lib/container_mesh.bash
+++ b/tests/e2e/lib/container_mesh.bash
@@ -278,8 +278,9 @@ if [[ -z "${MESH_HELPERS_LOADED:-}" ]]; then
local output
output="$(timeout 15s docker run --rm --network "${MESH_NETWORK}" "${MESH_RUNTIME_IMAGE}" mcp-client -url "http://${MESH_PREFIX}-node-${idx}:8080/mcp" -tool "get_mesh_info" 2>/dev/null)"
echo "Node ${idx} get_mesh_info raw output: ${output}"
+ # Peers other than the routers the node holds.
local count
- count="$(echo "${output}" | jq 'if .connected_peers then (.connected_peers | length) - 1 else 0 end')"
+ count="$(echo "${output}" | jq 'if .connected_peers then ((.connected_peers - (.attached_routers // [])) | length) else 0 end')"
echo "Node ${idx} reported known peers count: ${count}"
if [[ "${count}" -eq "${expected}" ]]; then
return 0
@@ -289,6 +290,26 @@ if [[ -z "${MESH_HELPERS_LOADED:-}" ]]; then
return 1
}
+ # mesh_wait_for_attached_routers waits until the node holds expected routers.
+ mesh_wait_for_attached_routers() {
+ local idx="$1"
+ local expected="$2"
+ local timeout_s="${3:-20}"
+ local i
+ for ((i=0; i<timeout_s; i++)); do
+ local output
+ output="$(timeout 15s docker run --rm --network "${MESH_NETWORK}" "${MESH_RUNTIME_IMAGE}" mcp-client -url "http://${MESH_PREFIX}-node-${idx}:8080/mcp" -tool "get_mesh_info" 2>/dev/null)"
+ local count
+ count="$(echo "${output}" | jq '.attached_routers // [] | length')"
+ echo "Node ${idx} holds ${count} router(s)"
+ if [[ "${count}" -eq "${expected}" ]]; then
+ return 0
+ fi
+ sleep 1
+ done
+ return 1
+ }
+
mesh_wait_for_peer_connection() {
local idx="$1"
local target_peer="$2"
diff --git a/tests/e2e/relay.bats b/tests/e2e/relay.bats
index 623e35d6..fb5ccd6e 100644
--- a/tests/e2e/relay.bats
+++ b/tests/e2e/relay.bats
@@ -122,19 +122,10 @@ EOF
[[ -n "${node2_peer_id}" ]]
MESH_NETWORK=$OLD_NET
- # Assert on the specific peer, not on set size: a relayed connection can leave
- # extra entries in connected_peers, so "length - 1" is not a stable count.
- run mesh_wait_for_peer_connection "1" "${node2_peer_id}" 60
- [[ "$status" -eq 0 ]]
-
- OLD_NET=$MESH_NETWORK
- MESH_NETWORK=$MESH_NETWORK_2
- run mesh_wait_for_peer_connection "2" "${node1_peer_id}" 60
- [[ "$status" -eq 0 ]]
- MESH_NETWORK=$OLD_NET
-
- # 2. Test HTTP Datapath: Node 2 calls Node 1's HTTP service via Node 2's egress proxy (isolated network 2)
- for ((i=0; i<15; i++)); do
+ # 2. Test HTTP Datapath: Node 2 calls Node 1's HTTP service via Node 2's
+ # egress proxy (isolated network 2). The nodes are on networks that cannot
+ # reach each other, so the call is what connects them, through the router.
+ for ((i=0; i<30; i++)); do
run docker run --rm --network "${MESH_NETWORK_2}" python:3.12 python3 -c "
import urllib.request
req = urllib.request.Request(
@@ -153,5 +144,17 @@ with urllib.request.urlopen(req) as response:
[[ "$status" -eq 0 ]]
[[ "$output" == *"{\"status\":\"success\"}"* ]]
+ # The call left the two connected, through the relay. Assert on the
+ # specific peer, not on set size: a relayed connection can leave extra
+ # entries in connected_peers.
+ run mesh_wait_for_peer_connection "1" "${node2_peer_id}" 30
+ [[ "$status" -eq 0 ]]
+
+ OLD_NET=$MESH_NETWORK
+ MESH_NETWORK=$MESH_NETWORK_2
+ run mesh_wait_for_peer_connection "2" "${node1_peer_id}" 30
+ [[ "$status" -eq 0 ]]
+ MESH_NETWORK=$OLD_NET
+
docker network rm "${MESH_NETWORK_2}" >/dev/null 2>&1 || true
}