t0060-daemon.sh 4.3 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

Jeromy's avatar
Jeromy committed
12
test_init_ipfs
Stephen Whitmore's avatar
Stephen Whitmore committed
13
test_launch_ipfs_daemon
14

Stephen Whitmore's avatar
Stephen Whitmore committed
15
# this errors if we didn't --init $IPFS_PATH correctly
16
test_expect_success "'ipfs config Identity.PeerID' works" '
Łukasz Magiera's avatar
Łukasz Magiera committed
17
  PEERID=$(ipfs config Identity.PeerID)
18 19
'

20
test_expect_success "'ipfs swarm addrs local' works" '
Łukasz Magiera's avatar
Łukasz Magiera committed
21
  ipfs swarm addrs local >local_addrs
22 23
'

24
test_expect_success "ipfs swarm addrs listen; works" '
Łukasz Magiera's avatar
Łukasz Magiera committed
25
  ipfs swarm addrs listen >listen_addrs
26 27
'

28
test_expect_success "ipfs peer id looks good" '
Łukasz Magiera's avatar
Łukasz Magiera committed
29
  test_check_peerid "$PEERID"
30 31
'

rht's avatar
rht committed
32 33 34
# 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" '
Łukasz Magiera's avatar
Łukasz Magiera committed
35
  curl -s -X GET -H "Origin:http://localhost:$API_PORT" -I "http://$API_ADDR/api/v0/version"
rht's avatar
rht committed
36 37 38
'

test_expect_success "ipfs gateway works with the correct allowed origin port" '
Łukasz Magiera's avatar
Łukasz Magiera committed
39
  curl -s -X GET -H "Origin:http://localhost:$GWAY_PORT" -I "http://$GWAY_ADDR/api/v0/version"
rht's avatar
rht committed
40 41
'

42
test_expect_success "ipfs daemon output looks good" '
Łukasz Magiera's avatar
Łukasz Magiera committed
43 44
  STARTFILE="ipfs cat /ipfs/$HASH_WELCOME_DOCS/readme" &&
  echo "Initializing daemon..." >expected_daemon &&
Overbool's avatar
Overbool committed
45
  ipfs version --all >> expected_daemon &&
Łukasz Magiera's avatar
Łukasz Magiera committed
46 47 48 49 50 51
  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 &&
  echo "Gateway (readonly) server listening on '$GWAY_MADDR'" >>expected_daemon &&
  echo "Daemon is ready" >>expected_daemon &&
  test_cmp expected_daemon actual_daemon
52 53
'

54
test_expect_success ".ipfs/ has been created" '
Łukasz Magiera's avatar
Łukasz Magiera committed
55 56 57 58 59
  test -d ".ipfs" &&
  test -f ".ipfs/config" &&
  test -d ".ipfs/datastore" &&
  test -d ".ipfs/blocks" ||
  test_fsh ls -al .ipfs
60 61
'

62 63 64
# begin same as in t0010

test_expect_success "ipfs version succeeds" '
Łukasz Magiera's avatar
Łukasz Magiera committed
65
  ipfs version >version.txt
66 67 68
'

test_expect_success "ipfs version output looks good" '
Łukasz Magiera's avatar
Łukasz Magiera committed
69 70
  egrep "^ipfs version [0-9]+\.[0-9]+\.[0-9]" version.txt >/dev/null ||
  test_fsh cat version.txt
71 72 73
'

test_expect_success "ipfs help succeeds" '
Łukasz Magiera's avatar
Łukasz Magiera committed
74
  ipfs help >help.txt
75 76 77
'

test_expect_success "ipfs help output looks good" '
Łukasz Magiera's avatar
Łukasz Magiera committed
78 79 80
  egrep -i "^Usage" help.txt >/dev/null &&
  egrep "ipfs .* <command>" help.txt >/dev/null ||
  test_fsh cat help.txt
81 82
'

Christian Couder's avatar
Christian Couder committed
83 84
# netcat (nc) is needed for the following test
test_expect_success "nc is available" '
Łukasz Magiera's avatar
Łukasz Magiera committed
85
  type nc >/dev/null
Christian Couder's avatar
Christian Couder committed
86
'
87

Christian Couder's avatar
Christian Couder committed
88
# check transport is encrypted
rht's avatar
rht committed
89
test_expect_success "transport should be encrypted" '
Łukasz Magiera's avatar
Łukasz Magiera committed
90 91 92 93
  nc -w 1 localhost $SWARM_PORT > swarmnc < ../t0060-data/mss-ls &&
  grep -q "/secio" swarmnc &&
  test_must_fail grep -q "/plaintext/1.0.0" swarmnc ||
  test_fsh cat swarmnc
94 95
'

96
test_expect_success "output from streaming commands works" '
Łukasz Magiera's avatar
Łukasz Magiera committed
97
  test_expect_code 28 curl -m 5 http://localhost:$API_PORT/api/v0/stats/bw\?poll=true > statsout
98 99 100
'

test_expect_success "output looks good" '
Łukasz Magiera's avatar
Łukasz Magiera committed
101 102 103 104
  grep TotalIn statsout > /dev/null &&
  grep TotalOut statsout > /dev/null &&
  grep RateIn statsout > /dev/null &&
  grep RateOut statsout >/dev/null
105 106
'

107 108
# end same as in t0010

109
test_expect_success "daemon is still running" '
Łukasz Magiera's avatar
Łukasz Magiera committed
110
  kill -0 $IPFS_PID
111 112 113
'

test_expect_success "'ipfs daemon' can be killed" '
Łukasz Magiera's avatar
Łukasz Magiera committed
114
  test_kill_repeat_10_sec $IPFS_PID
115 116
'

117
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
118 119 120 121
  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
122 123 124
'

test_expect_success "daemon with pipe eventually becomes live" '
Łukasz Magiera's avatar
Łukasz Magiera committed
125 126 127
  pollEndpoint -host='$API_MADDR' -ep=/version -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
128 129
'

130
ulimit -S -n 512
Jeromy's avatar
Jeromy committed
131 132 133 134
TEST_ULIMIT_PRESET=1
test_launch_ipfs_daemon

test_expect_success "daemon raised its fd limit" '
Łukasz Magiera's avatar
Łukasz Magiera committed
135
  grep "raised file descriptor limit to 2048." actual_daemon > /dev/null
Jeromy's avatar
Jeromy committed
136 137
'

138
test_expect_success "daemon actually can handle 2048 file descriptors" '
Łukasz Magiera's avatar
Łukasz Magiera committed
139
  hang-fds -hold=2s 2000 '$API_MADDR' > /dev/null
140 141 142
'

test_expect_success "daemon didnt throw any errors" '
Łukasz Magiera's avatar
Łukasz Magiera committed
143
  test_expect_code 1 grep "too many open files" daemon_err
144
'
145

Jeromy's avatar
Jeromy committed
146 147
test_kill_ipfs_daemon

148
test_done