mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-30 01:52:26 +08:00
daemon: fix output + time waiting
This commit is contained in:
@ -1,8 +1,8 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
ma "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"
|
ma "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"
|
||||||
cmds "github.com/jbenet/go-ipfs/commands"
|
cmds "github.com/jbenet/go-ipfs/commands"
|
||||||
@ -51,9 +51,8 @@ the daemon.
|
|||||||
}
|
}
|
||||||
|
|
||||||
func daemonFunc(req cmds.Request, res cmds.Response) {
|
func daemonFunc(req cmds.Request, res cmds.Response) {
|
||||||
var out bytes.Buffer
|
// let the user know we're going.
|
||||||
res.SetOutput(&out)
|
fmt.Printf("Initializing daemon...\n")
|
||||||
writef(&out, "Initializing daemon...\n")
|
|
||||||
|
|
||||||
// first, whether user has provided the initialization flag. we may be
|
// first, whether user has provided the initialization flag. we may be
|
||||||
// running in an uninitialized state.
|
// running in an uninitialized state.
|
||||||
@ -70,7 +69,7 @@ func daemonFunc(req cmds.Request, res cmds.Response) {
|
|||||||
// `IsInitialized` where the quality of the signal can be improved over
|
// `IsInitialized` where the quality of the signal can be improved over
|
||||||
// time, and many call-sites can benefit.
|
// time, and many call-sites can benefit.
|
||||||
if !util.FileExists(req.Context().ConfigRoot) {
|
if !util.FileExists(req.Context().ConfigRoot) {
|
||||||
err := initWithDefaults(&out, req.Context().ConfigRoot)
|
err := initWithDefaults(os.Stdout, req.Context().ConfigRoot)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
res.SetError(debugerror.Wrap(err), cmds.ErrNormal)
|
res.SetError(debugerror.Wrap(err), cmds.ErrNormal)
|
||||||
return
|
return
|
||||||
@ -155,8 +154,8 @@ func daemonFunc(req cmds.Request, res cmds.Response) {
|
|||||||
res.SetError(err, cmds.ErrNormal)
|
res.SetError(err, cmds.ErrNormal)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
writef(&out, "IPFS mounted at: %s\n", fsdir)
|
fmt.Printf("IPFS mounted at: %s\n", fsdir)
|
||||||
writef(&out, "IPNS mounted at: %s\n", nsdir)
|
fmt.Printf("IPNS mounted at: %s\n", nsdir)
|
||||||
}
|
}
|
||||||
|
|
||||||
var rootRedirect corehttp.ServeOption
|
var rootRedirect corehttp.ServeOption
|
||||||
@ -173,10 +172,6 @@ func daemonFunc(req cmds.Request, res cmds.Response) {
|
|||||||
writable = cfg.Gateway.Writable
|
writable = cfg.Gateway.Writable
|
||||||
}
|
}
|
||||||
|
|
||||||
if writable {
|
|
||||||
fmt.Printf("IPNS gateway mounted read-write\n")
|
|
||||||
}
|
|
||||||
|
|
||||||
if gatewayMaddr != nil {
|
if gatewayMaddr != nil {
|
||||||
go func() {
|
go func() {
|
||||||
var opts = []corehttp.ServeOption{corehttp.GatewayOption(writable)}
|
var opts = []corehttp.ServeOption{corehttp.GatewayOption(writable)}
|
||||||
@ -184,6 +179,9 @@ func daemonFunc(req cmds.Request, res cmds.Response) {
|
|||||||
opts = append(opts, rootRedirect)
|
opts = append(opts, rootRedirect)
|
||||||
}
|
}
|
||||||
fmt.Printf("Gateway server listening on %s\n", gatewayMaddr)
|
fmt.Printf("Gateway server listening on %s\n", gatewayMaddr)
|
||||||
|
if writable {
|
||||||
|
fmt.Printf("Gateway server is writable\n")
|
||||||
|
}
|
||||||
err := corehttp.ListenAndServe(node, gatewayMaddr.String(), opts...)
|
err := corehttp.ListenAndServe(node, gatewayMaddr.String(), opts...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(err)
|
log.Error(err)
|
||||||
|
@ -74,15 +74,16 @@ test_run_repeat_10_sec() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
test_wait_output_n_lines_60_sec() {
|
test_wait_output_n_lines_60_sec() {
|
||||||
echo "$2" >expected_waitn
|
for i in 1 2 3 4 5 6
|
||||||
|
do
|
||||||
for i in 1 2 3 4 5 6 7 8 9 10
|
for i in 1 2 3 4 5 6 7 8 9 10
|
||||||
do
|
do
|
||||||
cat "$1" | wc -l | tr -d " " >actual_waitn
|
test $(cat "$1" | wc -l | tr -d " ") -ge $2 && return
|
||||||
test_cmp "expected_waitn" "actual_waitn" && return
|
sleep 1
|
||||||
sleep 2
|
|
||||||
done
|
done
|
||||||
cat "$1" | wc -l | tr -d " " >actual_waitn
|
done
|
||||||
test_cmp "expected_waitn" "actual_waitn"
|
actual=$(cat "$1" | wc -l | tr -d " ")
|
||||||
|
fsh "expected $2 lines of output. got $actual"
|
||||||
}
|
}
|
||||||
|
|
||||||
test_wait_open_tcp_port_10_sec() {
|
test_wait_open_tcp_port_10_sec() {
|
||||||
@ -130,6 +131,13 @@ test_config_ipfs_gateway_writable() {
|
|||||||
|
|
||||||
test_launch_ipfs_daemon() {
|
test_launch_ipfs_daemon() {
|
||||||
|
|
||||||
|
ADDR_API="/ip4/127.0.0.1/tcp/5001"
|
||||||
|
ADDR_GWAY=`ipfs config Addresses.Gateway`
|
||||||
|
NLINES="2"
|
||||||
|
if test "$ADDR_GWAY" != ""; then
|
||||||
|
NLINES="3"
|
||||||
|
fi
|
||||||
|
|
||||||
test_expect_success "'ipfs daemon' succeeds" '
|
test_expect_success "'ipfs daemon' succeeds" '
|
||||||
ipfs daemon >actual_daemon 2>daemon_err &
|
ipfs daemon >actual_daemon 2>daemon_err &
|
||||||
'
|
'
|
||||||
@ -138,19 +146,17 @@ test_launch_ipfs_daemon() {
|
|||||||
# and we make sure there are no errors
|
# and we make sure there are no errors
|
||||||
test_expect_success "'ipfs daemon' is ready" '
|
test_expect_success "'ipfs daemon' is ready" '
|
||||||
IPFS_PID=$! &&
|
IPFS_PID=$! &&
|
||||||
test_run_repeat_10_sec "cat actual_daemon | grep \"API server listening on\"" &&
|
test_wait_output_n_lines_60_sec actual_daemon $NLINES &&
|
||||||
printf "" >empty && test_cmp daemon_err empty ||
|
printf "" >empty && test_cmp daemon_err empty ||
|
||||||
fsh cat actual_daemon || fsh cat daemon_err
|
fsh cat actual_daemon || fsh cat daemon_err
|
||||||
'
|
'
|
||||||
|
|
||||||
ADDR_API="/ip4/127.0.0.1/tcp/5001"
|
|
||||||
test_expect_success "'ipfs daemon' output includes API address" '
|
test_expect_success "'ipfs daemon' output includes API address" '
|
||||||
cat actual_daemon | grep "API server listening on $ADDR_API" ||
|
cat actual_daemon | grep "API server listening on $ADDR_API" ||
|
||||||
fsh cat actual_daemon ||
|
fsh cat actual_daemon ||
|
||||||
fsh "cat actual_daemon | grep \"API server listening on $ADDR_API\""
|
fsh "cat actual_daemon | grep \"API server listening on $ADDR_API\""
|
||||||
'
|
'
|
||||||
|
|
||||||
ADDR_GWAY=`ipfs config Addresses.Gateway`
|
|
||||||
if test "$ADDR_GWAY" != ""; then
|
if test "$ADDR_GWAY" != ""; then
|
||||||
test_expect_success "'ipfs daemon' output includes Gateway address" '
|
test_expect_success "'ipfs daemon' output includes Gateway address" '
|
||||||
cat actual_daemon | grep "Gateway server listening on $ADDR_GWAY" ||
|
cat actual_daemon | grep "Gateway server listening on $ADDR_GWAY" ||
|
||||||
|
Reference in New Issue
Block a user