t0240: improvements
This: - uses startup_cluster() from iptb-lib.sh, - avoids running test_expect_success() inside test_expect_success() as it makes the output confusing, - makes the number of test nodes easily configurable. License: MIT Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
Christian Couder committed
Feb 4, 2016 at 22:36 UTC
91322346e2a1c3ce69a69e3575486438aea09689
1 file changed
+55
-66
test/sharness/t0240-republisher.sh
+55
-66
@@ -11,34 +11,22 @@ test_description="Test ipfs repo operations"
11
export DEBUG=true
12
13
setup_iptb() {
14
+ num_nodes="$1"
15
+ bound=$(expr "$num_nodes" - 1)
16
+
17
test_expect_success "iptb init" '
15
- iptb init -n4 --bootstrap none --port 0
18
+ iptb init -n$num_nodes --bootstrap none --port 0
19
'
20
18
- test_expect_success "set configs up" '
19
- for i in $(test_seq 0 3)
20
- do
21
- ipfsi $i config Ipns.RepublishPeriod 20s
22
- ipfsi $i config --json Ipns.ResolveCacheSize 0
23
- done
24
- '
21
+ for i in $(test_seq 0 "$bound")
22
+ do
23
+ test_expect_success "set configs up for node $i" '
24
+ ipfsi "$i" config Ipns.RepublishPeriod 20s &&
25
+ ipfsi "$i" config --json Ipns.ResolveCacheSize 0
26
+ '
27
+ done
28
26
- test_expect_success "start up nodes" '
27
- iptb start
28
- '
29
-
30
- test_expect_success "connect nodes" '
31
- iptb connect 0 1 &&
32
- iptb connect 0 2 &&
33
- iptb connect 0 3
34
- '
35
-
36
- test_expect_success "nodes have connections" '
37
- ipfsi 0 swarm peers | grep ipfs &&
38
- ipfsi 1 swarm peers | grep ipfs &&
39
- ipfsi 2 swarm peers | grep ipfs &&
40
- ipfsi 3 swarm peers | grep ipfs
41
- '
29
+ startup_cluster "$num_nodes"
30
}
31
32
teardown_iptb() {
@@ -48,62 +36,63 @@ teardown_iptb() {
36
}
37
38
verify_can_resolve() {
51
- node=$1
52
- name=$2
53
- expected=$3
54
-
55
- test_expect_success "node can resolve entry" '
56
- ipfsi $node name resolve $name > resolve
57
- '
58
-
59
- test_expect_success "output looks right" '
60
- printf "/ipfs/$expected\n" > expected &&
61
- test_cmp expected resolve
62
- '
39
+ num_nodes="$1"
40
+ bound=$(expr "$num_nodes" - 1)
41
+ name="$2"
42
+ expected="$3"
43
+ msg="$4"
44
+
45
+ for node in $(test_seq 0 "$bound")
46
+ do
47
+ test_expect_success "$msg: node $node can resolve entry" '
48
+ ipfsi "$node" name resolve "$name" > resolve
49
+ '
50
+
51
+ test_expect_success "$msg: output for node $node looks right" '
52
+ printf "/ipfs/$expected\n" > expected &&
53
+ test_cmp expected resolve
54
+ '
55
+ done
56
}
57
58
verify_cannot_resolve() {
66
- node=$1
67
- name=$2
68
-
69
- echo "verifying resolution fails on node $node"
70
- test_expect_success "node cannot resolve entry" '
71
- # TODO: this should work without the timeout option
72
- # but it currently hangs for some reason every so often
73
- test_expect_code 1 ipfsi $node name resolve --timeout=300ms $name
74
- '
59
+ num_nodes="$1"
60
+ bound=$(expr "$num_nodes" - 1)
61
+ name="$2"
62
+ msg="$3"
63
+
64
+ for node in $(test_seq 0 "$bound")
65
+ do
66
+ test_expect_success "$msg: resolution fails on node $node" '
67
+ # TODO: this should work without the timeout option
68
+ # but it currently hangs for some reason every so often
69
+ test_expect_code 1 ipfsi "$node" name resolve --timeout=300ms "$name"
70
+ '
71
+ done
72
}
73
77
-setup_iptb
74
+num_test_nodes=4
75
+
76
+setup_iptb "$num_test_nodes"
77
78
test_expect_success "publish succeeds" '
79
HASH=$(echo "foobar" | ipfsi 1 add -q) &&
80
ipfsi 1 name publish -t 5s $HASH
81
'
82
84
-test_expect_success "other nodes can resolve" '
85
- id=$(ipfsi 1 id -f "<id>") &&
86
- verify_can_resolve 0 $id $HASH &&
87
- verify_can_resolve 1 $id $HASH &&
88
- verify_can_resolve 2 $id $HASH &&
89
- verify_can_resolve 3 $id $HASH
83
+test_expect_success "get id succeeds" '
84
+ id=$(ipfsi 1 id -f "<id>")
85
'
86
92
-test_expect_success "after five seconds, records are invalid" '
93
- go-sleep 5s &&
94
- verify_cannot_resolve 0 $id &&
95
- verify_cannot_resolve 1 $id &&
96
- verify_cannot_resolve 2 $id &&
97
- verify_cannot_resolve 3 $id
98
-'
87
+verify_can_resolve "$num_test_nodes" "$id" "$HASH" "just after publishing"
88
100
-test_expect_success "republisher fires after twenty seconds" '
101
- go-sleep 15s &&
102
- verify_can_resolve 0 $id $HASH &&
103
- verify_can_resolve 1 $id $HASH &&
104
- verify_can_resolve 2 $id $HASH &&
105
- verify_can_resolve 3 $id $HASH
106
-'
89
+go-sleep 5s
90
+
91
+verify_cannot_resolve "$num_test_nodes" "$id" "after five seconds, records are invalid"
92
+
93
+go-sleep 15s
94
+
95
+verify_can_resolve "$num_test_nodes" "$id" "$HASH" "republisher fires after twenty seconds"
96
97
teardown_iptb
98