reprovider: strategy tests
License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
Łukasz Magiera committed
Aug 1, 2017 at 17:46 UTC
279a5606606bb0e7c8816feced68f13bac92865d
1 file changed
+128
test/sharness/t0175-reprovider.sh
new
+128
@@ -0,0 +1,128 @@
1
+#!/bin/sh
2
+
3
+test_description="Test reprovider"
4
+
5
+. lib/test-lib.sh
6
+
7
+init_strategy() {
8
+ NUM_NODES=2
9
+ test_expect_success 'init iptb' '
10
+ iptb init -f -n $NUM_NODES --bootstrap=none --port=0
11
+ '
12
+
13
+ test_expect_success 'peer ids' '
14
+ PEERID_0=$(iptb get id 0) &&
15
+ PEERID_1=$(iptb get id 1)
16
+ '
17
+
18
+ test_expect_success 'use pinning startegy for reprovider' '
19
+ ipfsi 0 config Reprovider.Strategy '$1'
20
+ '
21
+
22
+ test_expect_success 'start peers' '
23
+ iptb start 0 &&
24
+ iptb start 1 &&
25
+ iptb connect 0 1
26
+ '
27
+}
28
+
29
+findprovs_empty() {
30
+ test_expect_success 'findprovs succeeds' '
31
+ ipfsi 1 dht findprovs -n 1 '$1' > findprovsOut
32
+ '
33
+
34
+ test_expect_success "findprovs output is empty" '
35
+ test_must_be_empty findprovsOut
36
+ '
37
+}
38
+
39
+findprovs_expect() {
40
+ test_expect_success 'findprovs succeeds' '
41
+ ipfsi 1 dht findprovs -n 1 '$1' > findprovsOut &&
42
+ echo '$2' > expected
43
+ '
44
+
45
+ test_expect_success "findprovs output looks good" '
46
+ test_cmp findprovsOut expected
47
+ '
48
+}
49
+
50
+reprovide() {
51
+ test_expect_success 'reprovide' '
52
+ # TODO: this hangs, though only after reprovision was done
53
+ ipfsi 0 bitswap reprovide
54
+ '
55
+}
56
+
57
+test_expect_success 'stop peer 1' '
58
+ iptb stop 1
59
+'
60
+
61
+# Test 'all' strategy
62
+init_strategy 'all'
63
+
64
+test_expect_success 'add test object' '
65
+ HASH_0=$(echo "foo" | ipfsi 0 add -q --local)
66
+'
67
+
68
+findprovs_empty '$HASH_0'
69
+reprovide
70
+findprovs_expect '$HASH_0' '$PEERID_0'
71
+
72
+# Test 'pinned' strategy
73
+init_strategy 'pinned'
74
+
75
+test_expect_success 'prepare test files' '
76
+ echo foo > f1 &&
77
+ echo bar > f2
78
+'
79
+
80
+test_expect_success 'add test objects' '
81
+ HASH_FOO=$(ipfsi 0 add -q --local --pin=false f1) &&
82
+ HASH_BAR=$(ipfsi 0 add -q --local --pin=false f2) &&
83
+ HASH_BAR_DIR=$(ipfsi 0 add -q --local -w f2)
84
+'
85
+
86
+findprovs_empty '$HASH_FOO'
87
+findprovs_empty '$HASH_BAR'
88
+findprovs_empty '$HASH_BAR_DIR'
89
+
90
+reprovide
91
+
92
+findprovs_empty '$HASH_FOO'
93
+findprovs_expect '$HASH_BAR' '$PEERID_0'
94
+findprovs_expect '$HASH_BAR_DIR' '$PEERID_0'
95
+
96
+test_expect_success 'stop peer 1' '
97
+ iptb stop 1
98
+'
99
+
100
+# Test 'roots' strategy
101
+init_strategy 'roots'
102
+
103
+test_expect_success 'prepare test files' '
104
+ echo foo > f1 &&
105
+ echo bar > f2
106
+'
107
+
108
+test_expect_success 'add test objects' '
109
+ HASH_FOO=$(ipfsi 0 add -q --local --pin=false f1) &&
110
+ HASH_BAR=$(ipfsi 0 add -q --local --pin=false f2) &&
111
+ HASH_BAR_DIR=$(ipfsi 0 add -q --local -w f2)
112
+'
113
+
114
+findprovs_empty '$HASH_FOO'
115
+findprovs_empty '$HASH_BAR'
116
+findprovs_empty '$HASH_BAR_DIR'
117
+
118
+reprovide
119
+
120
+findprovs_empty '$HASH_FOO'
121
+findprovs_empty '$HASH_BAR'
122
+findprovs_expect '$HASH_BAR_DIR' '$PEERID_0'
123
+
124
+test_expect_success 'stop peer 1' '
125
+ iptb stop 1
126
+'
127
+
128
+test_done