GO : go test -v 测试错误:panic: test timed out after 10m0s 。。。exit status 2

go test -v 测试时可能会遇到的错误“:

panic: test timed out after 10m0s

这导致了:我在测试用例中使用websocket发收数据时遇到的新的问题:

err write tcp IP1:9001->IP2:56240: write: broken pipe

Broken pipe产生的原因通常是当管道读端没有在读,而管道的写端继续有线程在写,就会造成管道中断。(由于管道是单向通信的) SIGSEGV(Segment fault)意味着指针所对应的地址是无效地址,没有物理内存对应该地址。

go test -v 详细错误信息如下:

goroutine 16 [running]:
testing.(*M).startAlarm.func1()
        /usr/local/go/src/testing/testing.go:1377 +0xdf
created by time.goFunc
        /usr/local/go/src/time/sleep.go:168 +0x44

goroutine 1 [chan receive]:
testing.(*T).Run(0xc000022200, 0x7c0e26, 0x18, 0x7d4890, 0x47fa06)
        /usr/local/go/src/testing/testing.go:961 +0x377
testing.runTests.func1(0xc000022100)
        /usr/local/go/src/testing/testing.go:1202 +0x78
testing.tRunner(0xc000022100, 0xc00008fdc0)
        /usr/local/go/src/testing/testing.go:909 +0xc9
testing.runTests(0xc00000ee60, 0xa59e20, 0x2, 0x2, 0x0)
        /usr/local/go/src/testing/testing.go:1200 +0x2a7
testing.(*M).Run(0xc000114080, 0x0)
        /usr/local/go/src/testing/testing.go:1117 +0x176
main.main()
        _testmain.go:46 +0x135

goroutine 7 [sleep]:
runtime.goparkunlock(...)
        /usr/local/go/src/runtime/proc.go:310
time.Sleep(0x2540be400)
        /usr/local/go/src/runtime/time.go:105 +0x157
grasper/apps/transpond/controllers.TestDlWebsocket_Progress.func1()
        /data/NR_XView/grasper/apps/transpond/controllers/simulateAnalysis_test.go:26 +0xd6
github.com/smartystreets/goconvey/convey.parseAction.func1(0x838000, 0xc0000a8420)
        /root/go/pkg/mod/github.com/smartystreets/[email protected]/convey/discovery.go:80 +0x24
github.com/smartystreets/goconvey/convey.(*context).conveyInner(0xc0000a8420, 0x7be425, 0x11, 0xc000093000)
        /root/go/pkg/mod/github.com/smartystreets/[email protected]/convey/context.go:261 +0x1b2
github.com/smartystreets/goconvey/convey.rootConvey.func1()
        /root/go/pkg/mod/github.com/smartystreets/[email protected]/convey/context.go:110 +0xfb
github.com/jtolds/gls.(*ContextManager).SetValues.func1(0x0)
        /root/go/pkg/mod/github.com/jtolds/[email protected]+incompatible/context.go:97 +0x466
github.com/jtolds/gls.EnsureGoroutineId.func1()
        /root/go/pkg/mod/github.com/jtolds/[email protected]+incompatible/gid.go:24 +0x2e
github.com/jtolds/gls._m(0x0, 0xc00000ef00)
        /root/go/pkg/mod/github.com/jtolds/[email protected]+incompatible/stack_tags.go:108 +0x31
github.com/jtolds/gls.github_com_jtolds_gls_markS(0x0, 0xc00000ef00)
        /root/go/pkg/mod/github.com/jtolds/[email protected]+incompatible/stack_tags.go:56 +0x35
github.com/jtolds/gls.addStackTag(...)
        /root/go/pkg/mod/github.com/jtolds/[email protected]+incompatible/stack_tags.go:49
github.com/jtolds/gls.EnsureGoroutineId(0xc000013530)
        /root/go/pkg/mod/github.com/jtolds/[email protected]+incompatible/gid.go:24 +0xdf
github.com/jtolds/gls.(*ContextManager).SetValues(0xc000092f00, 0xc0000134d0, 0xc00000eec0)
        /root/go/pkg/mod/github.com/jtolds/[email protected]+incompatible/context.go:63 +0x14b
github.com/smartystreets/goconvey/convey.rootConvey(0xc00007ef30, 0x3, 0x3)
        /root/go/pkg/mod/github.com/smartystreets/[email protected]/convey/context.go:105 +0x227
github.com/smartystreets/goconvey/convey.Convey(0xc00007ef30, 0x3, 0x3)
        /root/go/pkg/mod/github.com/smartystreets/[email protected]/convey/doc.go:75 +0xbe
grasper/apps/transpond/controllers.TestDlWebsocket_Progress(0xc000022200)
        /data/NR_XView/grasper/apps/transpond/controllers/simulateAnalysis_test.go:24 +0x10f
testing.tRunner(0xc000022200, 0x7d4890)
        /usr/local/go/src/testing/testing.go:909 +0xc9
created by testing.(*T).Run
        /usr/local/go/src/testing/testing.go:960 +0x350
exit status 2
解决方案: go test -timeout duration

timeout 的默认 值:duration=10m

 把duration设置为大于你测试用例所需的时间就行行了.

你可能感兴趣的:(Go)