| 1 | # iptb test framework |
| 2 | # |
| 3 | # Copyright (c) 2014, 2016 Jeromy Johnson, Christian Couder |
| 4 | # MIT Licensed; see the LICENSE file in this repository. |
| 5 | |
| 6 | export IPTB_ROOT="$(pwd)/.iptb" |
| 7 | |
| 8 | ipfsi() { |
| 9 | dir="$1" |
| 10 | shift |
| 11 | IPFS_PATH="$IPTB_ROOT/testbeds/default/$dir" ipfs "$@" |
| 12 | } |
| 13 | |
| 14 | check_has_connection() { |
| 15 | node="$1" |
| 16 | ipfsi "$node" swarm peers >"swarm_peers_$node" && |
| 17 | grep "p2p" "swarm_peers_$node" >/dev/null |
| 18 | } |
| 19 | |
| 20 | iptb() { |
| 21 | if ! command iptb "$@"; then |
| 22 | case "$1" in |
| 23 | start|stop|connect) |
| 24 | test_fsh command iptb logs |
| 25 | ;; |
| 26 | esac |
| 27 | return 1 |
| 28 | fi |
| 29 | } |
| 30 | |
| 31 | startup_cluster() { |
| 32 | num_nodes="$1" |
| 33 | shift |
| 34 | other_args="$@" |
| 35 | bound=$(expr "$num_nodes" - 1) |
| 36 | |
| 37 | test_expect_success "set Routing.LoopbackAddressesOnLanDHT to true" ' |
| 38 | iptb run [0-$bound] -- ipfs config --json "Routing.LoopbackAddressesOnLanDHT" true |
| 39 | ' |
| 40 | |
| 41 | if test -n "$other_args"; then |
| 42 | test_expect_success "start up nodes with additional args" " |
| 43 | iptb start -wait [0-$bound] -- ${other_args[@]} |
| 44 | " |
| 45 | else |
| 46 | test_expect_success "start up nodes" ' |
| 47 | iptb start -wait [0-$bound] |
| 48 | ' |
| 49 | fi |
| 50 | |
| 51 | test_expect_success "connect nodes to each other" ' |
| 52 | iptb connect [1-$bound] 0 |
| 53 | ' |
| 54 | |
| 55 | for i in $(test_seq 0 "$bound") |
| 56 | do |
| 57 | test_expect_success "node $i is connected" ' |
| 58 | check_has_connection "$i" || |
| 59 | test_fsh cat "swarm_peers_$i" |
| 60 | ' |
| 61 | done |
| 62 | } |
| 63 | |
| 64 | iptb_wait_stop() { |
| 65 | while ! iptb run -- sh -c '! { test -e "$IPFS_PATH/repo.lock" && fuser -f "$IPFS_PATH/repo.lock" >/dev/null; }'; do |
| 66 | go-sleep 10ms |
| 67 | done |
| 68 | } |