-
-
Notifications
You must be signed in to change notification settings - Fork 3k
/
Copy patht0060-daemon.sh
executable file
·211 lines (167 loc) · 6.59 KB
/
t0060-daemon.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
#!/usr/bin/env bash
#
# Copyright (c) 2014 Juan Batiz-Benet
# MIT Licensed; see the LICENSE file in this repository.
#
test_description="Test daemon command"
. lib/test-lib.sh
test_expect_success "create badger config" '
ipfs init --profile=badgerds,test > /dev/null &&
cp "$IPFS_PATH/config" init-config
'
test_expect_success "cleanup repo" '
rm -rf "$IPFS_PATH"
'
test_launch_ipfs_daemon --init --init-config="$(pwd)/init-config" --init-profile=test
test_kill_ipfs_daemon
test_expect_success "daemon initialization with existing config works" '
ipfs config "Datastore.Spec.child.path" >actual &&
test $(cat actual) = "badgerds" &&
ipfs config Addresses > orig_addrs
'
test_expect_success "cleanup repo" '
rm -rf "$IPFS_PATH"
'
test_launch_ipfs_daemon --init --init-config="$(pwd)/init-config" --init-profile=test,randomports
test_kill_ipfs_daemon
test_expect_success "daemon initialization with existing config + profiles works" '
ipfs config Addresses >new_addrs &&
test_expect_code 1 diff -q new_addrs orig_addrs
'
test_expect_success "cleanup repo" '
rm -rf "$IPFS_PATH"
'
test_init_ipfs
test_expect_success "set Resource Manager variables showed at startup" '
ipfs config --json Swarm.ResourceMgr.MaxFileDescriptors 1024 &&
ipfs config Swarm.ResourceMgr.MaxMemory 4GB
'
test_launch_ipfs_daemon
# this errors if we didn't --init $IPFS_PATH correctly
test_expect_success "'ipfs config Identity.PeerID' works" '
PEERID=$(ipfs config Identity.PeerID)
'
test_expect_success "'ipfs swarm addrs local' works" '
ipfs swarm addrs local >local_addrs
'
test_expect_success "ipfs swarm addrs listen; works" '
ipfs swarm addrs listen >listen_addrs
'
test_expect_success "ipfs peer id looks good" '
test_check_peerid "$PEERID"
'
# this is for checking SetAllowedOrigins race condition for the api and gateway
# See https://github.com/ipfs/go-ipfs/pull/1966
test_expect_success "ipfs API works with the correct allowed origin port" '
curl -s -X POST -H "Origin:http://localhost:$API_PORT" -I "http://$API_ADDR/api/v0/version"
'
test_expect_success "ipfs gateway works with the correct allowed origin port" '
curl -s -X POST -H "Origin:http://localhost:$GWAY_PORT" -I "http://$GWAY_ADDR/api/v0/version"
'
test_expect_success "ipfs daemon output includes looks good" '
test_should_contain "Initializing daemon..." actual_daemon &&
test_should_contain "$(ipfs version --all)" actual_daemon &&
test_should_contain "PeerID: $(ipfs config Identity.PeerID)" actual_daemon &&
test_should_contain "Swarm listening on 127.0.0.1:" actual_daemon &&
test_should_contain "RPC API server listening on '$API_MADDR'" actual_daemon &&
test_should_contain "WebUI: http://'$API_ADDR'/webui" actual_daemon &&
test_should_contain "Gateway server listening on '$GWAY_MADDR'" actual_daemon &&
test_should_contain "Daemon is ready" actual_daemon &&
cat actual_daemon
'
test_expect_success ".ipfs/ has been created" '
test -d ".ipfs" &&
test -f ".ipfs/config" &&
test -d ".ipfs/datastore" &&
test -d ".ipfs/blocks" ||
test_fsh ls -al .ipfs
'
# begin same as in t0010
test_expect_success "ipfs version succeeds" '
ipfs version >version.txt
'
test_expect_success "ipfs version output looks good" '
egrep "^ipfs version [0-9]+\.[0-9]+\.[0-9]" version.txt >/dev/null ||
test_fsh cat version.txt
'
test_expect_success "ipfs version deps succeeds" '
ipfs version deps >deps.txt
'
test_expect_success "ipfs version deps output looks good ( set \$GOIPFSTEST_SKIP_LOCAL_DEVTREE_DEPS_CHECK to skip this test )" '
head -1 deps.txt | grep "go-ipfs@(devel)" &&
[[ "$GOIPFSTEST_SKIP_LOCAL_DEVTREE_DEPS_CHECK" == "1" ]] ||
[[ $(tail -n +2 deps.txt | egrep -v -c "^[^ @]+@v[^ @]+( => [^ @]+@v[^ @]+)?$") -eq 0 ]] ||
test_fsh cat deps.txt
'
test_expect_success "ipfs help succeeds" '
ipfs help >help.txt
'
test_expect_success "ipfs help output looks good" '
egrep -i "^Usage" help.txt >/dev/null &&
egrep "ipfs .* <command>" help.txt >/dev/null ||
test_fsh cat help.txt
'
# check transport is encrypted by default and no plaintext is allowed
test_expect_success SOCAT "default transport should support encryption (TLS, needs socat )" '
socat - tcp:localhost:$SWARM_PORT,connect-timeout=1 > swarmnc < ../t0060-data/mss-tls &&
grep -q "/tls" swarmnc &&
test_must_fail grep -q "na" swarmnc ||
test_fsh cat swarmnc
'
test_expect_success SOCAT "default transport should support encryption (Noise, needs socat )" '
socat - tcp:localhost:$SWARM_PORT,connect-timeout=1 > swarmnc < ../t0060-data/mss-noise &&
grep -q "/noise" swarmnc &&
test_must_fail grep -q "na" swarmnc ||
test_fsh cat swarmnc
'
test_expect_success SOCAT "default transport should not support plaintext (needs socat )" '
socat - tcp:localhost:$SWARM_PORT,connect-timeout=1 > swarmnc < ../t0060-data/mss-plaintext &&
grep -q "na" swarmnc &&
test_must_fail grep -q "/plaintext" swarmnc ||
test_fsh cat swarmnc
'
test_expect_success "output from streaming commands works" '
test_expect_code 28 curl -X POST -m 5 http://localhost:$API_PORT/api/v0/stats/bw\?poll=true > statsout
'
test_expect_success "output looks good" '
grep TotalIn statsout > /dev/null &&
grep TotalOut statsout > /dev/null &&
grep RateIn statsout > /dev/null &&
grep RateOut statsout >/dev/null
'
# end same as in t0010
test_expect_success "daemon is still running" '
kill -0 $IPFS_PID
'
test_expect_success "'ipfs daemon' can be killed" '
test_kill_repeat_10_sec $IPFS_PID
'
test_expect_success "'ipfs daemon' should be able to run with a pipe attached to stdin (issue #861)" '
yes | ipfs daemon >stdin_daemon_out 2>stdin_daemon_err &
DAEMON_PID=$!
test_wait_for_file 20 100ms "$IPFS_PATH/api" &&
test_set_address_vars stdin_daemon_out
'
test_expect_success "daemon with pipe eventually becomes live" '
pollEndpoint -host='$API_MADDR' -v -tout=1s -tries=10 >stdin_poll_apiout 2>stdin_poll_apierr &&
test_kill_repeat_10_sec $DAEMON_PID ||
test_fsh cat stdin_daemon_out || test_fsh cat stdin_daemon_err || test_fsh cat stdin_poll_apiout || test_fsh cat stdin_poll_apierr
'
test_expect_success "'ipfs daemon' cleans up when it fails to start" '
test_must_fail ipfs daemon --routing=foobar &&
test ! -e "$IPFS_PATH/repo.lock"
'
ulimit -S -n 512
TEST_ULIMIT_PRESET=1
test_launch_ipfs_daemon
test_expect_success "daemon raised its fd limit" '
grep -v "setting file descriptor limit" actual_daemon > /dev/null
'
test_expect_success "daemon actually can handle 2048 file descriptors" '
hang-fds -hold=2s 2000 '$API_MADDR' > /dev/null
'
test_expect_success "daemon didn't throw any errors" '
test_expect_code 1 grep "too many open files" daemon_err
'
test_kill_ipfs_daemon
test_done