gossipsub sharness test
just a copy of t0180-pubsub with gossipsub enabled for now License: MIT Signed-off-by: vyzo <vyzo@hackzen.org>
vyzo committed
Aug 12, 2018 at 13:38 UTC
884df033205cd399e25d386a0334497d78788c56
1 file changed
+100
test/sharness/t0180-pubsub-gossipsub.sh
new
+100
@@ -0,0 +1,100 @@
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 init -n $NUM_NODES --bootstrap=none --port=0
11
+'
12
+
13
+test_expect_success "enable gossipsub" '
14
+ for x in $(seq 0 4); do
15
+ ipfsi 0 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 get id 0) &&
24
+ PEERID_2=$(iptb get id 2)
25
+'
26
+
27
+test_expect_success 'pubsub' '
28
+ echo "testOK" > 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=ndpayload testTopic | if read line; then
37
+ echo $line > 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" '
57
+ ipfsi 1 pubsub pub testTopic "testOK" &> pubErr
58
+'
59
+
60
+test_expect_success "wait until echo > wait executed" '
61
+ cat wait &&
62
+ test_cmp pubErr empty &&
63
+ test_cmp expected actual
64
+'
65
+
66
+test_expect_success "wait for another pubsub message" '
67
+ echo "testOK2" > expected &&
68
+ mkfifo wait2 ||
69
+ test_fsh echo init fail
70
+
71
+ # ipfs pubsub sub is long-running so we need to start it in the background and
72
+ # wait put its output somewhere where we can access it
73
+ (
74
+ ipfsi 2 pubsub sub --enc=ndpayload testTopic | if read line; then
75
+ echo $line > actual &&
76
+ echo > wait2
77
+ fi
78
+ ) &
79
+'
80
+
81
+test_expect_success "wait until ipfs pubsub sub is ready to do work" '
82
+ go-sleep 500ms
83
+'
84
+
85
+test_expect_success "publish something" '
86
+ echo "testOK2" | ipfsi 1 pubsub pub testTopic &> pubErr
87
+'
88
+
89
+test_expect_success "wait until echo > wait executed" '
90
+ echo "testOK2" > expected &&
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