`go test` for package fails but individually test run fine, and package compiles fine

huangapple go评论100阅读模式
英文:

`go test` for package fails but individually test run fine, and package compiles fine

问题

当我执行go test来测试整个包时,测试失败并显示以下错误信息:

$ go test github.com/dm03514/go-edu-db/...
# github.com/dm03514/go-edu-db/backends
go1: internal compiler error: in read_type, at go/gofrontend/import.cc:669
Please submit a full bug report,
with preprocessed source if appropriate.
See <file:///usr/share/doc/gccgo-4.9/README.Bugs> for instructions.
FAIL    github.com/dm03514/go-edu-db/backends [build failed]
?       github.com/dm03514/go-edu-db/cmd        [no test files]
# github.com/dm03514/go-edu-db/httpd
go1: internal compiler error: in read_type, at go/gofrontend/import.cc:669
Please submit a full bug report,
with preprocessed source if appropriate.
See <file:///usr/share/doc/gccgo-4.9/README.Bugs> for instructions.
FAIL    github.com/dm03514/go-edu-db/httpd [build failed]
?       github.com/dm03514/go-edu-db/logging    [no test files]

尽管上述测试失败,但go install命令可以正确构建,并且我可以正确运行每个单独的测试文件:

$ go test github.com/dm03514/go-edu-db/backends/backends_test.go
ok      command-line-arguments  0.025s


go test github.com/dm03514/go-edu-db/httpd/handlers_test.go
ok      command-line-arguments  0.021s

有人遇到过这个问题吗?我对Go还是很新,为了解决这个问题,我一直在逐个执行我的测试文件。

go build命令的输出为空:

$ go build github.com/dm03514/go-edu-db/...
$

我的go版本是:

$ go version
go version xgcc (Ubuntu 4.9-20140406-0ubuntu1) 4.9.0 20140405 (experimental) [trunk revision 209157] linux/amd64
英文:

When I execute go test for a whole package the tests fail with:

$ go test github.com/dm03514/go-edu-db/...
# github.com/dm03514/go-edu-db/backends
go1: internal compiler error: in read_type, at go/gofrontend/import.cc:669
Please submit a full bug report,
with preprocessed source if appropriate.
See &lt;file:///usr/share/doc/gccgo-4.9/README.Bugs&gt; for instructions.
FAIL    github.com/dm03514/go-edu-db/backends [build failed]
?       github.com/dm03514/go-edu-db/cmd        [no test files]
# github.com/dm03514/go-edu-db/httpd
go1: internal compiler error: in read_type, at go/gofrontend/import.cc:669
Please submit a full bug report,
with preprocessed source if appropriate.
See &lt;file:///usr/share/doc/gccgo-4.9/README.Bugs&gt; for instructions.
FAIL    github.com/dm03514/go-edu-db/httpd [build failed]
?       github.com/dm03514/go-edu-db/logging    [no test files]

While the above tests fail go install builds correctly and I can run each of my individual tests correctly:

$ go test github.com/dm03514/go-edu-db/backends/backends_test.go
ok      command-line-arguments  0.025s


go test github.com/dm03514/go-edu-db/httpd/handlers_test.go
ok      command-line-arguments  0.021s

Has anyone ran into this before? I am brand new to Go, and to get around this I have just been executing each one of my test files individually.

The output of go build is nothing

$ go build github.com/dm03514/go-edu-db/...
$

go version is

$ go version
go version xgcc (Ubuntu 4.9-20140406-0ubuntu1) 4.9.0 20140405 (experimental) [trunk revision 209157] linux/amd64

答案1

得分: 2

这也发生在我身上。我最后只是将不同的测试注释掉,直到能够看到有用的输出并且知道何时开始通过。根本原因是我同时运行的一个测试 goroutine 在测试完成后调用了 t.Errorf(具体来说,我使用的是 testify/assert 包,但最终它会调用 t.Errorf)。使用 go test -v 命令输出的错误信息如下:

> Fail in goroutine after TestTradeReader_Subscribe has completed

对我来说,这是因为我在测试中使用了一个 httptest.Server(在我的测试期间并发运行),并且在一个快速退出且不需要此检查的测试用例上进行了输入检查。

英文:

This happened to me as well. I ended up just commenting out different tests until I was able to see useful output and to see when it would start passing. The root cause was one of my concurrently running test goroutines was calling t.Errorf (specifically, I was using the testify/assert package, but this eventually calls t.Errorf) after the test was completed. The output using go test -v eventually had this error message:

> Fail in goroutine after TestTradeReader_Subscribe has completed

For me, this happened because I was using an httptest.Server (which runs concurrently during my test) and was checking input on a test case that exited quickly and didn't require this check.

答案2

得分: 0

帮助我解决问题的方法是:如果你在循环中使用了大量的测试,并且在循环外创建了一些模拟服务,可能会导致一些问题。

要解决这个问题:只需将复杂测试中创建模拟对象的步骤移到循环内部即可解决!

英文:

The thing that helped me.. If you use plenty of tests in a loop and you create some of the mocked services OUTSIDE the loop, it may cause some problem.

TO SOLVE THIS: just move your mocked objects creation for your complex tests inside the loop and it will be done!

答案3

得分: -2

可能存在一个例行泄漏。你可能在测试中修改/更新了一个全局变量,并且没有在第二个测试中恢复。
导致这个错误的第二个原因可能是你的测试没有在封闭的环境中运行,并且影响了其他测试。
你可以重新组织你的测试,使得出现错误的测试首先运行,这样它就能成功通过。

英文:

There is probably a routine leak. You maybe be modifying/updating a global variable in the test and not reverting for the second test.
Second reason for this error could be your test in not running in a closed env. and effecting other test after.
you can re-structure your test so that the test giving error runs at first so that it succeeds

huangapple
  • 本文由 发表于 2015年6月15日 01:40:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/30832540.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定