t0060-daemon.sh 5.78 KB
Newer Older
Łukasz Magiera's avatar
Łukasz Magiera committed
1
#!/usr/bin/env bash
2 3 4 5 6 7 8 9 10
#
# Copyright (c) 2014 Juan Batiz-Benet
# MIT Licensed; see the LICENSE file in this repository.
#

test_description="Test daemon command"

. lib/test-lib.sh

11
test_expect_success "create badger config" '
12
  ipfs init --profile=badgerds,test > /dev/null &&
13 14
  cp "$IPFS_PATH/config" init-config
'
Dominic Della Valle's avatar
Dominic Della Valle committed
15

16 17
test_expect_success "cleanup repo" '
  rm -rf "$IPFS_PATH"
Dominic Della Valle's avatar
Dominic Della Valle committed
18 19
'

20
test_launch_ipfs_daemon --init --init-config="$(pwd)/init-config" --init-profile=test
Dominic Della Valle's avatar
Dominic Della Valle committed
21 22 23 24
test_kill_ipfs_daemon

test_expect_success "daemon initialization with existing config works" '
  ipfs config "Datastore.Spec.child.path" >actual &&
25 26
  test $(cat actual) = "badgerds" &&
  ipfs config Addresses > orig_addrs
Dominic Della Valle's avatar
Dominic Della Valle committed
27 28
'

29 30
test_expect_success "cleanup repo" '
  rm -rf "$IPFS_PATH"
Dominic Della Valle's avatar
Dominic Della Valle committed
31
'
32

33
test_launch_ipfs_daemon --init --init-config="$(pwd)/init-config" --init-profile=test,randomports
Dominic Della Valle's avatar
Dominic Della Valle committed
34 35
test_kill_ipfs_daemon

36 37 38
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
Dominic Della Valle's avatar
Dominic Della Valle committed
39 40
'

41 42
test_expect_success "cleanup repo" '
  rm -rf "$IPFS_PATH"
Dominic Della Valle's avatar
Dominic Della Valle committed
43
'
44

Jeromy's avatar
Jeromy committed
45
test_init_ipfs
Stephen Whitmore's avatar
Stephen Whitmore committed
46
test_launch_ipfs_daemon
47

Stephen Whitmore's avatar
Stephen Whitmore committed
48
# this errors if we didn't --init $IPFS_PATH correctly
49
test_expect_success "'ipfs config Identity.PeerID' works" '
Łukasz Magiera's avatar
Łukasz Magiera committed
50
  PEERID=$(ipfs config Identity.PeerID)
51 52
'

53
test_expect_success "'ipfs swarm addrs local' works" '
Łukasz Magiera's avatar
Łukasz Magiera committed
54
  ipfs swarm addrs local >local_addrs
55 56
'

57
test_expect_success "ipfs swarm addrs listen; works" '
Łukasz Magiera's avatar
Łukasz Magiera committed
58
  ipfs swarm addrs listen >listen_addrs
59 60
'

61
test_expect_success "ipfs peer id looks good" '
Łukasz Magiera's avatar
Łukasz Magiera committed
62
  test_check_peerid "$PEERID"
63 64
'

rht's avatar
rht committed
65 66 67
# 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" '
68
  curl -s -X POST -H "Origin:http://localhost:$API_PORT" -I "http://$API_ADDR/api/v0/version"
rht's avatar
rht committed
69 70 71
'

test_expect_success "ipfs gateway works with the correct allowed origin port" '
72
  curl -s -X POST -H "Origin:http://localhost:$GWAY_PORT" -I "http://$GWAY_ADDR/api/v0/version"
rht's avatar
rht committed
73 74
'

75
test_expect_success "ipfs daemon output looks good" '
Łukasz Magiera's avatar
Łukasz Magiera committed
76 77
  STARTFILE="ipfs cat /ipfs/$HASH_WELCOME_DOCS/readme" &&
  echo "Initializing daemon..." >expected_daemon &&
Overbool's avatar
Overbool committed
78
  ipfs version --all >> expected_daemon &&
Łukasz Magiera's avatar
Łukasz Magiera committed
79 80 81
  sed "s/^/Swarm listening on /" listen_addrs >>expected_daemon &&
  sed "s/^/Swarm announcing /" local_addrs >>expected_daemon &&
  echo "API server listening on '$API_MADDR'" >>expected_daemon &&
82
  echo "WebUI: http://'$API_ADDR'/webui" >>expected_daemon &&
Łukasz Magiera's avatar
Łukasz Magiera committed
83 84 85
  echo "Gateway (readonly) server listening on '$GWAY_MADDR'" >>expected_daemon &&
  echo "Daemon is ready" >>expected_daemon &&
  test_cmp expected_daemon actual_daemon
86 87
'

88
test_expect_success ".ipfs/ has been created" '
Łukasz Magiera's avatar
Łukasz Magiera committed
89 90 91 92 93
  test -d ".ipfs" &&
  test -f ".ipfs/config" &&
  test -d ".ipfs/datastore" &&
  test -d ".ipfs/blocks" ||
  test_fsh ls -al .ipfs
94 95
'

96 97 98
# begin same as in t0010

test_expect_success "ipfs version succeeds" '
Łukasz Magiera's avatar
Łukasz Magiera committed
99
  ipfs version >version.txt
100 101 102
'

test_expect_success "ipfs version output looks good" '
Łukasz Magiera's avatar
Łukasz Magiera committed
103 104
  egrep "^ipfs version [0-9]+\.[0-9]+\.[0-9]" version.txt >/dev/null ||
  test_fsh cat version.txt
105 106
'

107 108 109 110
test_expect_success "ipfs version deps succeeds" '
  ipfs version deps >deps.txt
'

111
test_expect_success "ipfs version deps output looks good ( set \$GOIPFSTEST_SKIP_LOCAL_DEVTREE_DEPS_CHECK to skip this test )" '
112
  head -1 deps.txt | grep "go-ipfs@(devel)" &&
113
  [[ "$GOIPFSTEST_SKIP_LOCAL_DEVTREE_DEPS_CHECK" == "1" ]] ||
114 115 116 117
  [[ $(tail -n +2 deps.txt | egrep -v -c "^[^ @]+@v[^ @]+( => [^ @]+@v[^ @]+)?$") -eq 0 ]] ||
  test_fsh cat deps.txt
'

118
test_expect_success "ipfs help succeeds" '
Łukasz Magiera's avatar
Łukasz Magiera committed
119
  ipfs help >help.txt
120 121 122
'

test_expect_success "ipfs help output looks good" '
Łukasz Magiera's avatar
Łukasz Magiera committed
123 124 125
  egrep -i "^Usage" help.txt >/dev/null &&
  egrep "ipfs .* <command>" help.txt >/dev/null ||
  test_fsh cat help.txt
126 127
'

Christian Couder's avatar
Christian Couder committed
128
# check transport is encrypted
129
test_expect_success SOCAT "transport should be encrypted ( needs socat )" '
Jakub Sztandera's avatar
Jakub Sztandera committed
130
  socat - tcp:localhost:$SWARM_PORT,connect-timeout=1 > swarmnc < ../t0060-data/mss-ls &&
Łukasz Magiera's avatar
Łukasz Magiera committed
131 132 133
  grep -q "/secio" swarmnc &&
  test_must_fail grep -q "/plaintext/1.0.0" swarmnc ||
  test_fsh cat swarmnc
134 135
'

136
test_expect_success "output from streaming commands works" '
137
  test_expect_code 28 curl -X POST -m 5 http://localhost:$API_PORT/api/v0/stats/bw\?poll=true > statsout
138 139 140
'

test_expect_success "output looks good" '
Łukasz Magiera's avatar
Łukasz Magiera committed
141 142 143 144
  grep TotalIn statsout > /dev/null &&
  grep TotalOut statsout > /dev/null &&
  grep RateIn statsout > /dev/null &&
  grep RateOut statsout >/dev/null
145 146
'

147 148
# end same as in t0010

149
test_expect_success "daemon is still running" '
Łukasz Magiera's avatar
Łukasz Magiera committed
150
  kill -0 $IPFS_PID
151 152 153
'

test_expect_success "'ipfs daemon' can be killed" '
Łukasz Magiera's avatar
Łukasz Magiera committed
154
  test_kill_repeat_10_sec $IPFS_PID
155 156
'

157
test_expect_success "'ipfs daemon' should be able to run with a pipe attached to stdin (issue #861)" '
Łukasz Magiera's avatar
Łukasz Magiera committed
158 159 160 161
  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
Jeromy's avatar
Jeromy committed
162 163 164
'

test_expect_success "daemon with pipe eventually becomes live" '
165
  pollEndpoint -host='$API_MADDR' -v -tout=1s -tries=10 >stdin_poll_apiout 2>stdin_poll_apierr &&
Łukasz Magiera's avatar
Łukasz Magiera committed
166 167
  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
168 169
'

170 171 172 173 174
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"
'

175
ulimit -S -n 512
Jeromy's avatar
Jeromy committed
176 177 178 179
TEST_ULIMIT_PRESET=1
test_launch_ipfs_daemon

test_expect_success "daemon raised its fd limit" '
180
  grep -v "setting file descriptor limit" actual_daemon > /dev/null
Jeromy's avatar
Jeromy committed
181 182
'

183
test_expect_success "daemon actually can handle 2048 file descriptors" '
Łukasz Magiera's avatar
Łukasz Magiera committed
184
  hang-fds -hold=2s 2000 '$API_MADDR' > /dev/null
185 186
'

Dimitris Apostolou's avatar
Dimitris Apostolou committed
187
test_expect_success "daemon didn't throw any errors" '
Łukasz Magiera's avatar
Łukasz Magiera committed
188
  test_expect_code 1 grep "too many open files" daemon_err
189
'
190

Jeromy's avatar
Jeromy committed
191 192
test_kill_ipfs_daemon

193
test_done