4 回答
TA貢獻(xiàn)2051條經(jīng)驗(yàn) 獲得超10個(gè)贊
我懷疑錯(cuò)誤信息:
Unable to start NATS Server in Go Routine
具有誤導(dǎo)性。關(guān)于 Go 例程的部分可能只是它如何嘗試啟動(dòng) NATS 服務(wù)器的實(shí)現(xiàn)細(xì)節(jié)。我懷疑服務(wù)器無法啟動(dòng),因?yàn)槟谶x項(xiàng)中對端口進(jìn)行了硬編碼,并且因?yàn)槎鄠€(gè)測試包可能正在并行運(yùn)行。只有一個(gè)測試包能夠綁定到端口來啟動(dòng) NATS 服務(wù)器,所有其他測試包都將失敗。
標(biāo)志上的文檔go test說:
-parallel n
Allow parallel execution of test functions that call t.Parallel.
The value of this flag is the maximum number of tests to run
simultaneously; by default, it is set to the value of GOMAXPROCS.
Note that -parallel only applies within a single test binary.
The 'go test' command may run tests for different packages
in parallel as well, according to the setting of the -p flag
(see 'go help build').
除非您在給定的測試套件中有并行測試(我假設(shè)您沒有),否則問題可能是并行運(yùn)行的不同包。按照上面末尾的線索,讓我們看看構(gòu)建標(biāo)志:
-p n
the number of programs, such as build commands or
test binaries, that can be run in parallel.
The default is the number of CPUs available.
這是來自“編譯包和依賴項(xiàng)”文檔。請注意,您可以將構(gòu)建標(biāo)志和測試標(biāo)志傳遞給go test:
$ go test -h
usage: go test [build/test flags] [packages] [build/test flags & test binary flags]
Run 'go help test' for details.
所以考慮跑步go test -p 1 ./...?;蛘?,將選項(xiàng)傳遞給RunServer函數(shù),允許多個(gè)選項(xiàng)安全地并行發(fā)生。
TA貢獻(xiàn)1765條經(jīng)驗(yàn) 獲得超5個(gè)贊
每次測試它可能已經(jīng)啟動(dòng)了一個(gè)服務(wù)器。沒有 goroutine 就無法同時(shí)運(yùn)行。這個(gè)錯(cuò)誤實(shí)際上沒有任何意義 - Go 中的任何東西都必須能夠在 goroutine 中運(yùn)行,事實(shí)上一切都在goroutine 中運(yùn)行(甚至main),所以不清楚他們在這里真正想說的是什么(我會絕對建議打開有關(guān)它的錯(cuò)誤報(bào)告,因?yàn)樵撳e(cuò)誤消息很糟糕)。同時(shí),您可以避免go test同時(shí)運(yùn)行-parallel 1(如 中所示go help testflag),這可能會有所幫助。
TA貢獻(xiàn)1921條經(jīng)驗(yàn) 獲得超9個(gè)贊
就我而言,問題是我已經(jīng)運(yùn)行了一個(gè) nats-server 實(shí)例,因此測試失敗。通過停止服務(wù)器,測試成功通過。
- 4 回答
- 0 關(guān)注
- 326 瀏覽
添加回答
舉報(bào)
