| 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | test_description="Test pubsub with gossipsub" |
| 4 | |
| 5 | . lib/test-lib.sh |
| 6 | |
| 7 | # start iptb + wait for peering |
| 8 | NUM_NODES=5 |
| 9 | test_expect_success 'init iptb' ' |
| 10 | iptb testbed create -type localipfs -count $NUM_NODES -init |
| 11 | ' |
| 12 | |
| 13 | test_expect_success "enable gossipsub" ' |
| 14 | for x in $(seq 0 4); do |
| 15 | ipfsi $x config Pubsub.Router gossipsub |
| 16 | done |
| 17 | ' |
| 18 | |
| 19 | # this is just a copy of t0180-pubsub; smell. |
| 20 | startup_cluster $NUM_NODES --enable-pubsub-experiment |
| 21 | |
| 22 | test_expect_success 'peer ids' ' |
| 23 | PEERID_0=$(iptb attr get 0 id) && |
| 24 | PEERID_2=$(iptb attr get 2 id) |
| 25 | ' |
| 26 | |
| 27 | test_expect_success 'pubsub' ' |
| 28 | echo -n -e "test\nOK" | ipfs multibase encode -b base64url > expected && |
| 29 | touch empty && |
| 30 | mkfifo wait || |
| 31 | test_fsh echo init fail |
| 32 | |
| 33 | # ipfs pubsub sub is long-running so we need to start it in the background and |
| 34 | # wait put its output somewhere where we can access it |
| 35 | ( |
| 36 | ipfsi 0 pubsub sub --enc=json testTopic | if read line; then |
| 37 | echo $line | jq -j .data > actual && |
| 38 | echo > wait |
| 39 | fi |
| 40 | ) & |
| 41 | ' |
| 42 | |
| 43 | test_expect_success "wait until ipfs pubsub sub is ready to do work" ' |
| 44 | go-sleep 500ms |
| 45 | ' |
| 46 | |
| 47 | test_expect_success "can see peer subscribed to testTopic" ' |
| 48 | ipfsi 1 pubsub peers testTopic > peers_out |
| 49 | ' |
| 50 | |
| 51 | test_expect_success "output looks good" ' |
| 52 | echo $PEERID_0 > peers_exp && |
| 53 | test_cmp peers_exp peers_out |
| 54 | ' |
| 55 | |
| 56 | test_expect_success "publish something from a file" ' |
| 57 | echo -n -e "test\nOK" > payload-file && |
| 58 | ipfsi 1 pubsub pub testTopic payload-file &> pubErr |
| 59 | ' |
| 60 | |
| 61 | test_expect_success "wait until echo > wait executed" ' |
| 62 | cat wait && |
| 63 | test_cmp pubErr empty && |
| 64 | test_cmp expected actual |
| 65 | ' |
| 66 | |
| 67 | test_expect_success "wait for another pubsub message" ' |
| 68 | echo -n -e "test\nOK2" | ipfs multibase encode -b base64url > expected && |
| 69 | mkfifo wait2 || |
| 70 | test_fsh echo init fail |
| 71 | |
| 72 | # ipfs pubsub sub is long-running so we need to start it in the background and |
| 73 | # wait put its output somewhere where we can access it |
| 74 | ( |
| 75 | ipfsi 2 pubsub sub --enc=json testTopic | if read line; then |
| 76 | echo $line | jq -j .data > actual && |
| 77 | echo > wait2 |
| 78 | fi |
| 79 | ) & |
| 80 | ' |
| 81 | |
| 82 | test_expect_success "wait until ipfs pubsub sub is ready to do work" ' |
| 83 | go-sleep 500ms |
| 84 | ' |
| 85 | |
| 86 | test_expect_success "publish something" ' |
| 87 | echo -n -e "test\nOK2" | ipfsi 1 pubsub pub testTopic &> pubErr |
| 88 | ' |
| 89 | |
| 90 | test_expect_success "wait until echo > wait executed" ' |
| 91 | cat wait2 && |
| 92 | test_cmp pubErr empty && |
| 93 | test_cmp expected actual |
| 94 | ' |
| 95 | |
| 96 | test_expect_success 'stop iptb' ' |
| 97 | iptb stop |
| 98 | ' |
| 99 | |
| 100 | test_done |