Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
56a32a30
提交
56a32a30
authored
3月 04, 2015
作者:
Henry
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
using pollEndpoint to block in tests for 'daemon ready' (updates #844)
上级
51a8bcbf
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
114 行增加
和
4 行删除
+114
-4
daemon.go
cmd/ipfs/daemon.go
+1
-0
main.go
cmd/pollEndpoint/main.go
+106
-0
Makefile
test/Makefile
+5
-1
test-lib.sh
test/sharness/lib/test-lib.sh
+2
-3
没有找到文件。
cmd/ipfs/daemon.go
浏览文件 @
56a32a30
...
...
@@ -244,6 +244,7 @@ func daemonFunc(req cmds.Request, res cmds.Response) {
corehttp
.
CommandsOption
(
*
req
.
Context
()),
corehttp
.
WebUIOption
,
gateway
.
ServeOption
(),
corehttp
.
VersionOption
(),
}
if
rootRedirect
!=
nil
{
opts
=
append
(
opts
,
rootRedirect
)
...
...
cmd/pollEndpoint/main.go
0 → 100644
浏览文件 @
56a32a30
// pollEndpoint is a helper utility that waits for a http endpoint to be reachable and return with http.StatusOK
package
main
import
(
"flag"
"net"
"net/http"
"net/url"
"os"
"syscall"
"time"
log
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/Sirupsen/logrus"
ma
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"
manet
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr-net"
)
var
(
host
=
flag
.
String
(
"host"
,
"/ip4/127.0.0.1/tcp/5001"
,
"the multiaddr host to dial on"
)
endpoint
=
flag
.
String
(
"ep"
,
"/version"
,
"which http endpoint path to hit"
)
tries
=
flag
.
Int
(
"tries"
,
10
,
"how many tries to make before failing"
)
timeout
=
flag
.
Duration
(
"tout"
,
time
.
Second
,
"how long to wait between attempts"
)
verbose
=
flag
.
Bool
(
"v"
,
false
,
"verbose logging"
)
)
func
main
()
{
flag
.
Parse
()
// extract address from host flag
addr
,
err
:=
ma
.
NewMultiaddr
(
*
host
)
if
err
!=
nil
{
log
.
WithField
(
"err"
,
err
)
.
Fatal
(
"NewMultiaddr() failed"
)
}
p
:=
addr
.
Protocols
()
if
len
(
p
)
<
2
{
log
.
WithField
(
"addr"
,
addr
)
.
Fatal
(
"need to protocolls in host flag."
)
}
_
,
host
,
err
:=
manet
.
DialArgs
(
addr
)
if
err
!=
nil
{
log
.
WithField
(
"err"
,
err
)
.
Fatal
(
"manet.DialArgs() failed"
)
}
if
*
verbose
{
// lower log level
log
.
SetLevel
(
log
.
DebugLevel
)
}
// construct url to dial
var
u
url
.
URL
u
.
Scheme
=
"http"
u
.
Host
=
host
u
.
Path
=
*
endpoint
// show what we got
start
:=
time
.
Now
()
log
.
WithFields
(
log
.
Fields
{
"when"
:
start
,
"tries"
:
*
tries
,
"timeout"
:
*
timeout
,
"url"
:
u
.
String
(),
})
.
Debug
(
"starting"
)
for
*
tries
>
0
{
f
:=
log
.
Fields
{
"tries"
:
*
tries
}
resp
,
err
:=
http
.
Get
(
u
.
String
())
if
err
==
nil
{
resp
.
Body
.
Close
()
if
resp
.
StatusCode
==
http
.
StatusOK
{
f
[
"took"
]
=
time
.
Since
(
start
)
log
.
WithFields
(
f
)
.
Println
(
"status ok - endpoint reachable"
)
os
.
Exit
(
0
)
}
f
[
"status"
]
=
resp
.
Status
log
.
WithFields
(
f
)
.
Warn
(
"response not okay"
)
}
else
if
urlErr
,
ok
:=
err
.
(
*
url
.
Error
);
ok
{
// expected error from http.Get()
f
[
"urlErr"
]
=
urlErr
if
urlErr
.
Op
!=
"Get"
||
urlErr
.
URL
!=
*
endpoint
{
f
[
"op"
]
=
urlErr
.
Op
f
[
"url"
]
=
urlErr
.
URL
log
.
WithFields
(
f
)
.
Error
(
"way to funky buisness..!"
)
}
if
opErr
,
ok
:=
urlErr
.
Err
.
(
*
net
.
OpError
);
ok
{
f
[
"opErr"
]
=
opErr
f
[
"connRefused"
]
=
opErr
.
Err
==
syscall
.
ECONNREFUSED
f
[
"temporary"
]
=
opErr
.
Temporary
()
log
.
WithFields
(
f
)
.
Println
(
"net.OpError"
)
}
}
else
{
// unexpected error from http.Get()
f
[
"err"
]
=
err
log
.
WithFields
(
f
)
.
Error
(
"unknown error"
)
}
time
.
Sleep
(
*
timeout
)
*
tries
--
}
log
.
Println
(
"failed."
)
os
.
Exit
(
1
)
}
test/Makefile
浏览文件 @
56a32a30
BINS
=
bin/random bin/multihash bin/ipfs
BINS
=
bin/random bin/multihash bin/ipfs
bin/pollEndpoint
IPFS_ROOT
=
../
IPFS_CMD
=
../cmd/ipfs
RANDOM_SRC
=
../Godeps/_workspace/src/github.com/jbenet/go-random
MULTIHASH_SRC
=
../Godeps/_workspace/src/github.com/jbenet/go-multihash
POLLENDPOINT_SRC
=
../cmd/pollEndpoint
all
:
deps
...
...
@@ -23,6 +24,9 @@ bin/multihash: $(MULTIHASH_SRC)/**/*.go
bin/ipfs
:
$(IPFS_ROOT)/**/*.go
go build
-o
bin/ipfs
$(IPFS_CMD)
bin/pollEndpoint
:
$(POLLENDPOINT_SRC)/*.go
go build
-o
bin/pollEndpoint
$(POLLENDPOINT_SRC)
test
:
test_expensive
test_expensive
:
...
...
test/sharness/lib/test-lib.sh
浏览文件 @
56a32a30
...
...
@@ -175,14 +175,13 @@ test_launch_ipfs_daemon() {
ADDR_API
=
"/ip4/127.0.0.1/tcp/5001"
test_expect_success
"'ipfs daemon' is ready"
'
IPFS_PID=$! &&
test_wait_output_n_lines_60_sec actual_daemon 2 &&
test_run_repeat_60_sec "grep \"API server listening on $ADDR_API\" actual_daemon" ||
pollEndpoint -ep=/version -host=$ADDR_API -v -tout=1s -tries=60 2>poll_err > poll_apiout ||
test_fsh cat actual_daemon || test_fsh cat daemon_err
'
if
test
"
$ADDR_GWAY
"
!=
""
;
then
test_expect_success
"'ipfs daemon' output includes Gateway address"
'
test_run_repeat_60_sec "grep \"Gateway server listening on $ADDR_GWAY\" actual_daemon"
||
pollEndpoint -ep=/version -host=$ADDR_GWAY -v -tout=1s -tries=60 2>poll_err > poll_gwout
||
test_fsh cat daemon_err
'
fi
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论