| 1 | #!/usr/bin/env bash |
| 2 | # |
| 3 | # Copyright (c) 2016 Jeromy Johnson |
| 4 | # MIT Licensed; see the LICENSE file in this repository. |
| 5 | # |
| 6 | |
| 7 | # changing the bootstrap peers will require changing it in two places :) |
| 8 | test_description="test node bootstrapping" |
| 9 | |
| 10 | . lib/test-lib.sh |
| 11 | |
| 12 | test_init_ipfs |
| 13 | |
| 14 | test_expect_success "disable mdns" ' |
| 15 | ipfs config Discovery.MDNS.Enabled false --json |
| 16 | ' |
| 17 | |
| 18 | test_launch_ipfs_daemon |
| 19 | |
| 20 | test_expect_success "setup iptb nodes" ' |
| 21 | iptb testbed create -type localipfs -count 5 -force -init |
| 22 | ' |
| 23 | |
| 24 | test_expect_success "start up iptb nodes" ' |
| 25 | iptb start -wait |
| 26 | ' |
| 27 | |
| 28 | test_expect_success "check peers works" ' |
| 29 | ipfs swarm peers >peers_out |
| 30 | ' |
| 31 | |
| 32 | test_expect_success "correct number of peers" ' |
| 33 | test -z "`cat peers_out`" |
| 34 | ' |
| 35 | |
| 36 | betterwait() { |
| 37 | while kill -0 $1; do true; done |
| 38 | } |
| 39 | |
| 40 | test_expect_success "bring down iptb nodes" ' |
| 41 | PID0=$(cat "$IPTB_ROOT/testbeds/default/0/daemon.pid") && |
| 42 | PID1=$(cat "$IPTB_ROOT/testbeds/default/1/daemon.pid") && |
| 43 | PID2=$(cat "$IPTB_ROOT/testbeds/default/2/daemon.pid") && |
| 44 | PID3=$(cat "$IPTB_ROOT/testbeds/default/3/daemon.pid") && |
| 45 | PID4=$(cat "$IPTB_ROOT/testbeds/default/4/daemon.pid") && |
| 46 | iptb stop && # TODO: add --wait flag to iptb stop |
| 47 | betterwait $PID0 |
| 48 | betterwait $PID1 |
| 49 | betterwait $PID2 |
| 50 | betterwait $PID3 |
| 51 | betterwait $PID4 |
| 52 | ' |
| 53 | |
| 54 | test_expect_success "reset iptb nodes" ' |
| 55 | # the api does not seem to get cleaned up in sharness tests for some reason |
| 56 | iptb testbed create -type localipfs -count 5 -force -init |
| 57 | ' |
| 58 | |
| 59 | test_expect_success "set bootstrap addrs" ' |
| 60 | bsn_peer_id=$(ipfs id -f "<id>") && |
| 61 | BADDR="/ip4/127.0.0.1/tcp/$SWARM_PORT/p2p/$bsn_peer_id" && |
| 62 | ipfsi 0 bootstrap add $BADDR && |
| 63 | ipfsi 1 bootstrap add $BADDR && |
| 64 | ipfsi 2 bootstrap add $BADDR && |
| 65 | ipfsi 3 bootstrap add $BADDR && |
| 66 | ipfsi 4 bootstrap add $BADDR |
| 67 | ' |
| 68 | |
| 69 | test_expect_success "start up iptb nodes" ' |
| 70 | iptb start -wait |
| 71 | ' |
| 72 | |
| 73 | test_expect_success "check peers works" ' |
| 74 | ipfs swarm peers > peers_out |
| 75 | ' |
| 76 | |
| 77 | test_expect_success "correct number of peers" ' |
| 78 | test `cat peers_out | wc -l` = 5 |
| 79 | ' |
| 80 | |
| 81 | test_kill_ipfs_daemon |
| 82 | |
| 83 | test_expect_success "bring down iptb nodes" ' |
| 84 | iptb stop |
| 85 | ' |
| 86 | |
| 87 | test_done |