Skip to content

Commit

Permalink
shell script for simple network-delay test
Browse files Browse the repository at this point in the history
  • Loading branch information
fixxxedpoint committed Nov 23, 2022
1 parent 8e82598 commit c13fedd
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions scripts/run_consensus_network_delay.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/bin/bash

set -euo pipefail

NETWORK_DELAY=${NETWORK_DELAY:-500}
BUILD_IMAGE=${BUILD_IMAGE:-true}
NODES=${NODES:-"Node0:Node1:Node2:Node3:Node4"}

function build_test_image() {
docker build -t aleph-node:network_tests -f docker/Dockerfile.network_tests .
}

function set_network_delay() {
local node=$1
local delay=$2

log "setting network delay for node $node"
docker exec $node tc qdisc add dev eth1 root netem delay ${delay}ms
}

function log() {
echo "$1" 1>&2
}

function into_array() {
result=()
local tmp=$IFS
IFS=:
for e in $1; do
result+=($e)
done
IFS=$tmp
}

into_array $NODES
NODES=(${result[@]})

if [[ "$BUILD_IMAGE" = true ]]; then
log "building docker image for network tests"
build_test_image
fi

log "starting network"
OVERRIDE_DOCKER_COMPOSE=./docker/docker-compose.network_test.yml DOCKER_COMPOSE=./docker/docker-compose.bridged.yml ./.github/scripts/run_consensus.sh 1>&2
log "network started"

log "setting network delay"
for node in ${NODES[@]}; do
set_network_delay $node $NETWORK_DELAY
done

log "done"

0 comments on commit c13fedd

Please sign in to comment.