去版本:1.18.1假設我寫了這個測試文件parallel_test.gopackage parallel_json_outputimport ( "fmt" "testing" "time")func TestP(t *testing.T) { t.Run("a", func(t *testing.T) { t.Parallel() for i := 0; i < 5; i++ { time.Sleep(time.Second) fmt.Println("a", i) } }) t.Run("b", func(t *testing.T) { t.Parallel() for i := 0; i < 5; i++ { time.Sleep(time.Second) fmt.Println("b", i) } })}跑步后go test parallel_test.go -v -json,我得到了{"Time":"2022-06-11T02:48:10.3262833+08:00","Action":"run","Package":"command-line-arguments","Test":"TestP"}{"Time":"2022-06-11T02:48:10.3672856+08:00","Action":"output","Package":"command-line-arguments","Test":"TestP","Output":"=== RUN TestP\n"}{"Time":"2022-06-11T02:48:10.3682857+08:00","Action":"run","Package":"command-line-arguments","Test":"TestP/a"}{"Time":"2022-06-11T02:48:10.3682857+08:00","Action":"output","Package":"command-line-arguments","Test":"TestP/a","Output":"=== RUN TestP/a\n"}{"Time":"2022-06-11T02:48:10.3692857+08:00","Action":"output","Package":"command-line-arguments","Test":"TestP/a","Output":"=== PAUSE TestP/a\n"}{"Time":"2022-06-11T02:48:10.3702858+08:00","Action":"pause","Package":"command-line-arguments","Test":"TestP/a"}...看看這一行{"Time":"2022-06-11T02:48:11.3352891+08:00","Action":"output","Package":"command-line-arguments","Test":"TestP/b","Output":"a 0\n"}。此輸出應按案例TestP/a而不是打印b,但輸出在并行測試中弄亂了案例名稱。這個問題使報告工具生成錯誤的 HTML 報告,IDE(如 GoLand)也受到影響,無法正確排序并行輸出。我在 Github here中發現了一個問題,但是這個問題似乎已經在 go 1.14.6 中得到修復,但是,它仍然出現在 go 1.18 中。我想知道發生了什么以及如何處理它,非常感謝。
- 1 回答
- 0 關注
- 123 瀏覽
添加回答
舉報
0/150
提交
取消