mirror of
https://github.com/weaveworks/scope.git
synced 2026-03-02 09:40:34 +00:00
Add integration test for procspy edges.
This commit is contained in:
@@ -1,21 +1,25 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -eux
|
||||
set -ex
|
||||
|
||||
readonly ARG="$1"
|
||||
|
||||
eval $(weave env)
|
||||
|
||||
start_container() {
|
||||
IMAGE=$2
|
||||
BASENAME=$3
|
||||
REPLICAS=$1
|
||||
local IMAGE=$2
|
||||
local BASENAME=$3
|
||||
local REPLICAS=$1
|
||||
shift 3
|
||||
HOSTNAME=$BASENAME.weave.local
|
||||
local HOSTNAME=$BASENAME.weave.local
|
||||
|
||||
for i in $(seq $REPLICAS); do
|
||||
if docker inspect $BASENAME$i >/dev/null 2>&1; then
|
||||
docker rm -f $BASENAME$i
|
||||
fi
|
||||
docker run -d --name=$BASENAME$i --hostname=$HOSTNAME $@ $IMAGE
|
||||
if [ "$ARG" != "-rm" ]; then
|
||||
docker run -d --name=$BASENAME$i --hostname=$HOSTNAME $@ $IMAGE
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ wait_for_containers $HOST1 60 nginx "The Internet"
|
||||
|
||||
has_container $HOST1 nginx
|
||||
has_container $HOST1 "The Internet"
|
||||
has_connection $HOST1 "The Internet" nginx
|
||||
has_connection containers $HOST1 "The Internet" nginx
|
||||
|
||||
kill %do_connections
|
||||
|
||||
|
||||
@@ -16,6 +16,6 @@ wait_for_containers $HOST1 60 nginx client
|
||||
|
||||
has_container $HOST1 nginx
|
||||
has_container $HOST1 client
|
||||
has_connection $HOST1 client nginx
|
||||
has_connection containers $HOST1 client nginx
|
||||
|
||||
scope_end_suite
|
||||
|
||||
@@ -21,7 +21,7 @@ sleep 30 # need to allow the scopes to poll dns, resolve the other app ids, and
|
||||
check() {
|
||||
has_container $1 nginx
|
||||
has_container $1 client
|
||||
has_connection $1 client nginx
|
||||
has_connection containers $1 client nginx
|
||||
}
|
||||
|
||||
check $HOST1
|
||||
|
||||
21
integration/330_application_edge_test.sh
Executable file
21
integration/330_application_edge_test.sh
Executable file
@@ -0,0 +1,21 @@
|
||||
#! /bin/bash
|
||||
|
||||
. ./config.sh
|
||||
|
||||
start_suite "Test short connections between processes"
|
||||
|
||||
WEAVE_DOCKER_ARGS=$ADD_HOST_ARGS weave_on $HOST1 launch
|
||||
scope_on $HOST1 launch
|
||||
weave_on $HOST1 run -d --name nginx nginx
|
||||
weave_on $HOST1 run -dti --name client alpine /bin/sh -c "while true; do \
|
||||
nc nginx.weave.local 80 || true; \
|
||||
sleep 1; \
|
||||
done"
|
||||
|
||||
wait_for application $HOST1 60 nginx client
|
||||
|
||||
has applications $HOST1 nginx
|
||||
has applications $HOST1 nc
|
||||
has_connection applications $HOST1 nc nginx
|
||||
|
||||
scope_end_suite
|
||||
30
integration/340_application_edge_across_host_2_test.sh
Executable file
30
integration/340_application_edge_across_host_2_test.sh
Executable file
@@ -0,0 +1,30 @@
|
||||
#! /bin/bash
|
||||
|
||||
. ./config.sh
|
||||
|
||||
start_suite "Test connections between processes on different hosts"
|
||||
|
||||
WEAVE_DOCKER_ARGS=$ADD_HOST_ARGS weave_on $HOST1 launch $HOST1 $HOST2
|
||||
WEAVE_DOCKER_ARGS=$ADD_HOST_ARGS weave_on $HOST2 launch $HOST1 $HOST2
|
||||
|
||||
scope_on $HOST1 launch
|
||||
scope_on $HOST2 launch
|
||||
|
||||
weave_on $HOST1 run -d --name nginx nginx
|
||||
weave_on $HOST2 run -dti --name client alpine /bin/sh -c "while true; do \
|
||||
nc nginx.weave.local 80 || true; \
|
||||
sleep 1; \
|
||||
done"
|
||||
|
||||
sleep 30 # need to allow the scopes to poll dns, resolve the other app ids, and send them reports
|
||||
|
||||
check() {
|
||||
has applications $1 nginx
|
||||
has applications $1 nc
|
||||
has_connection applications $1 nc nginx
|
||||
}
|
||||
|
||||
check $HOST1
|
||||
check $HOST2
|
||||
|
||||
scope_end_suite
|
||||
@@ -29,14 +29,6 @@ weave_on() {
|
||||
DOCKER_HOST=tcp://$host:$DOCKER_PORT $WEAVE "$@"
|
||||
}
|
||||
|
||||
# this checks we have a named container
|
||||
has_container() {
|
||||
local host=$1
|
||||
local name=$2
|
||||
local count=${3:-1}
|
||||
assert "curl -s http://$host:4040/api/topology/containers?system=show | jq -r '[.nodes[] | select(.label_major == \"$name\")] | length'" $count
|
||||
}
|
||||
|
||||
scope_end_suite() {
|
||||
end_suite
|
||||
for host in $HOSTS; do
|
||||
@@ -44,58 +36,84 @@ scope_end_suite() {
|
||||
done
|
||||
}
|
||||
|
||||
# this checks we have a named node in the given view
|
||||
has() {
|
||||
local view=$1
|
||||
local host=$2
|
||||
local name=$3
|
||||
local count=${4:-1}
|
||||
assert "curl -s http://${host}:4040/api/topology/${view}?system=show | jq -r '[.nodes[] | select(.label_major == \"${name}\")] | length'" $count
|
||||
}
|
||||
|
||||
# this checks we have a named container
|
||||
has_container() {
|
||||
has containers "$@"
|
||||
}
|
||||
|
||||
node_id() {
|
||||
local view="$1"
|
||||
local host="$2"
|
||||
local name="$3"
|
||||
echo $(curl -s http://${host}:4040/api/topology/${view}?system=show | jq -r ".nodes[] | select(.label_major == \"${name}\") | .id")
|
||||
}
|
||||
|
||||
container_id() {
|
||||
local host="$1"
|
||||
local name="$2"
|
||||
echo $(curl -s http://$host:4040/api/topology/containers?system=show | jq -r ".nodes[] | select(.label_major == \"$name\") | .id")
|
||||
node_id containers "$@"
|
||||
}
|
||||
|
||||
# this checks we have an edge from container 1 to container 2
|
||||
has_connection() {
|
||||
local host="$1"
|
||||
local from="$2"
|
||||
local to="$3"
|
||||
local timeout="${4:-60}"
|
||||
local from_id=$(container_id "$host" "$from")
|
||||
local to_id=$(container_id "$host" "$to")
|
||||
local view="$1"
|
||||
local host="$2"
|
||||
local from="$3"
|
||||
local to="$4"
|
||||
local timeout="${5:-60}"
|
||||
local from_id=$(node_id "${view}" "${host}" "${from}")
|
||||
local to_id=$(node_id "${view}" "${host}" "${to}")
|
||||
|
||||
for i in $(seq $timeout); do
|
||||
local containers="$(curl -s http://$host:4040/api/topology/containers?system=show)"
|
||||
local edge=$(echo "$containers" | jq -r ".nodes[\"$from_id\"].adjacency | contains([\"$to_id\"])" 2>/dev/null)
|
||||
local nodes="$(curl -s http://$host:4040/api/topology/${view}?system=show)"
|
||||
local edge=$(echo "$nodes" | jq -r ".nodes[\"$from_id\"].adjacency | contains([\"$to_id\"])" 2>/dev/null)
|
||||
if [ "$edge" = "true" ]; then
|
||||
echo "Found edge $from -> $to after $i secs"
|
||||
assert "curl -s http://$host:4040/api/topology/containers?system=show | jq -r '.nodes[\"$from_id\"].adjacency | contains([\"$to_id\"])'" true
|
||||
assert "curl -s http://$host:4040/api/topology/${view}?system=show | jq -r '.nodes[\"$from_id\"].adjacency | contains([\"$to_id\"])'" true
|
||||
return
|
||||
fi
|
||||
sleep 1
|
||||
done
|
||||
|
||||
echo "Failed to find edge $from -> $to after $timeout secs"
|
||||
assert "curl -s http://$host:4040/api/topology/containers?system=show | jq -r '.nodes[\"$from_id\"].adjacency | contains([\"$to_id\"])'" true
|
||||
assert "curl -s http://$host:4040/api/topology/${view}?system=show | jq -r '.nodes[\"$from_id\"].adjacency | contains([\"$to_id\"])'" true
|
||||
}
|
||||
|
||||
wait_for_containers() {
|
||||
local host="$1"
|
||||
local timeout="$2"
|
||||
wait_for() {
|
||||
local view="$1"
|
||||
local host="$2"
|
||||
local timeout="$3"
|
||||
shift 2
|
||||
|
||||
for i in $(seq $timeout); do
|
||||
local containers="$(curl -s http://$host:4040/api/topology/containers?system=show)"
|
||||
for i in $(seq ${timeout}); do
|
||||
local nodes="$(curl -s http://$host:4040/api/topology/${view}?system=show)"
|
||||
local found=0
|
||||
for name in "$@"; do
|
||||
local count=$(echo "$containers" | jq -r "[.nodes[] | select(.label_major == \"$name\")] | length")
|
||||
if [ -n "$count" ] && [ "$count" -ge 1 ]; then
|
||||
local count=$(echo "${nodes}" | jq -r "[.nodes[] | select(.label_major == \"${name}\")] | length")
|
||||
if [ -n "${count}" ] && [ "${count}" -ge 1 ]; then
|
||||
found=$(( found + 1 ))
|
||||
fi
|
||||
done
|
||||
|
||||
if [ "$found" -eq $# ]; then
|
||||
echo "Found $found containers after $i secs"
|
||||
if [ "${found}" -eq $# ]; then
|
||||
echo "Found ${found} nodes after $i secs"
|
||||
return
|
||||
fi
|
||||
|
||||
sleep 1
|
||||
done
|
||||
|
||||
echo "Failed to find containers $@ after $i secs"
|
||||
echo "Failed to find nodes $@ after $i secs"
|
||||
}
|
||||
|
||||
|
||||
wait_for_containers() {
|
||||
wait_for containers "$@"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user