@cryptotaxi247 / kubo / commits / c37225580

daemon: fix output + time waiting

Juan Batiz-Benet committed Feb 1, 2015 at 03:30 UTC c372255807122625b50c494b1af64aa0d5bc1ce5
2 files changed +25 -21
cmd/ipfs/daemon.go
+9 -11
@@ -1,8 +1,8 @@
1 package main
2
3 import (
4 - "bytes"
4 "fmt"
5 + "os"
6
7 ma "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"
8 cmds "github.com/jbenet/go-ipfs/commands"
@@ -51,9 +51,8 @@ the daemon.
51 }
52
53 func daemonFunc(req cmds.Request, res cmds.Response) {
54 - var out bytes.Buffer
55 - res.SetOutput(&out)
56 - writef(&out, "Initializing daemon...\n")
54 + // let the user know we're going.
55 + fmt.Printf("Initializing daemon...\n")
56
57 // first, whether user has provided the initialization flag. we may be
58 // running in an uninitialized state.
@@ -70,7 +69,7 @@ func daemonFunc(req cmds.Request, res cmds.Response) {
69 // `IsInitialized` where the quality of the signal can be improved over
70 // time, and many call-sites can benefit.
71 if !util.FileExists(req.Context().ConfigRoot) {
73 - err := initWithDefaults(&out, req.Context().ConfigRoot)
72 + err := initWithDefaults(os.Stdout, req.Context().ConfigRoot)
73 if err != nil {
74 res.SetError(debugerror.Wrap(err), cmds.ErrNormal)
75 return
@@ -155,8 +154,8 @@ func daemonFunc(req cmds.Request, res cmds.Response) {
154 res.SetError(err, cmds.ErrNormal)
155 return
156 }
158 - writef(&out, "IPFS mounted at: %s\n", fsdir)
159 - writef(&out, "IPNS mounted at: %s\n", nsdir)
157 + fmt.Printf("IPFS mounted at: %s\n", fsdir)
158 + fmt.Printf("IPNS mounted at: %s\n", nsdir)
159 }
160
161 var rootRedirect corehttp.ServeOption
@@ -173,10 +172,6 @@ func daemonFunc(req cmds.Request, res cmds.Response) {
172 writable = cfg.Gateway.Writable
173 }
174
176 - if writable {
177 - fmt.Printf("IPNS gateway mounted read-write\n")
178 - }
179 -
175 if gatewayMaddr != nil {
176 go func() {
177 var opts = []corehttp.ServeOption{corehttp.GatewayOption(writable)}
@@ -184,6 +179,9 @@ func daemonFunc(req cmds.Request, res cmds.Response) {
179 opts = append(opts, rootRedirect)
180 }
181 fmt.Printf("Gateway server listening on %s\n", gatewayMaddr)
182 + if writable {
183 + fmt.Printf("Gateway server is writable\n")
184 + }
185 err := corehttp.ListenAndServe(node, gatewayMaddr.String(), opts...)
186 if err != nil {
187 log.Error(err)
test/sharness/lib/test-lib.sh
+16 -10
@@ -74,15 +74,16 @@ test_run_repeat_10_sec() {
74 }
75
76 test_wait_output_n_lines_60_sec() {
77 - echo "$2" >expected_waitn
78 - for i in 1 2 3 4 5 6 7 8 9 10
77 + for i in 1 2 3 4 5 6
78 do
80 - cat "$1" | wc -l | tr -d " " >actual_waitn
81 - test_cmp "expected_waitn" "actual_waitn" && return
82 - sleep 2
79 + for i in 1 2 3 4 5 6 7 8 9 10
80 + do
81 + test $(cat "$1" | wc -l | tr -d " ") -ge $2 && return
82 + sleep 1
83 + done
84 done
84 - cat "$1" | wc -l | tr -d " " >actual_waitn
85 - test_cmp "expected_waitn" "actual_waitn"
85 + actual=$(cat "$1" | wc -l | tr -d " ")
86 + fsh "expected $2 lines of output. got $actual"
87 }
88
89 test_wait_open_tcp_port_10_sec() {
@@ -130,6 +131,13 @@ test_config_ipfs_gateway_writable() {
131
132 test_launch_ipfs_daemon() {
133
134 + ADDR_API="/ip4/127.0.0.1/tcp/5001"
135 + ADDR_GWAY=`ipfs config Addresses.Gateway`
136 + NLINES="2"
137 + if test "$ADDR_GWAY" != ""; then
138 + NLINES="3"
139 + fi
140 +
141 test_expect_success "'ipfs daemon' succeeds" '
142 ipfs daemon >actual_daemon 2>daemon_err &
143 '
@@ -138,19 +146,17 @@ test_launch_ipfs_daemon() {
146 # and we make sure there are no errors
147 test_expect_success "'ipfs daemon' is ready" '
148 IPFS_PID=$! &&
141 - test_run_repeat_10_sec "cat actual_daemon | grep \"API server listening on\"" &&
149 + test_wait_output_n_lines_60_sec actual_daemon $NLINES &&
150 printf "" >empty && test_cmp daemon_err empty ||
151 fsh cat actual_daemon || fsh cat daemon_err
152 '
153
146 - ADDR_API="/ip4/127.0.0.1/tcp/5001"
154 test_expect_success "'ipfs daemon' output includes API address" '
155 cat actual_daemon | grep "API server listening on $ADDR_API" ||
156 fsh cat actual_daemon ||
157 fsh "cat actual_daemon | grep \"API server listening on $ADDR_API\""
158 '
159
153 - ADDR_GWAY=`ipfs config Addresses.Gateway`
160 if test "$ADDR_GWAY" != ""; then
161 test_expect_success "'ipfs daemon' output includes Gateway address" '
162 cat actual_daemon | grep "Gateway server listening on $ADDR_GWAY" ||