概要
忘れない内にメモメモ。
テストをするために go test
を実行していると、たまに以下のようにキャッシュした結果を表示してるよって出る時があります。
- 1回目
$ go test -v github.com/devlights/gomy/chans -run ^TestFanOut$ === RUN TestFanOut TestFanOut: fanout_test.go:78: [workerCount=1][estimation] 700ms [elapsed] 601.3349ms TestFanOut: fanout_test.go:78: [workerCount=2][estimation] 400ms [elapsed] 302.4562ms TestFanOut: fanout_test.go:78: [workerCount=3][estimation] 300ms [elapsed] 200.512ms --- PASS: TestFanOut (1.10s) PASS ok github.com/devlights/gomy/chans 1.183s
- 2回目
$ go test -v github.com/devlights/gomy/chans -run ^TestFanOut$ === RUN TestFanOut TestFanOut: fanout_test.go:78: [workerCount=1][estimation] 700ms [elapsed] 601.3349ms TestFanOut: fanout_test.go:78: [workerCount=2][estimation] 400ms [elapsed] 302.4562ms TestFanOut: fanout_test.go:78: [workerCount=3][estimation] 300ms [elapsed] 200.512ms --- PASS: TestFanOut (1.10s) PASS ok github.com/devlights/gomy/chans (cached)
最後に (cached)
ってついてますね。
Goのサイトにも、これについて記載あります。
んで、このキャッシュを消す方法です。
キャッシュを消す方法
以下のコマンドで消えます。
$ go clean -testcache
毎回キャッシュ無視してテスト実行してもらう
以下のようにするとキャッシュ見ずにフレッシュにテストしてくれます。
go test -count=1 ....
-count=1
というのを付与すると、キャッシュを見ずにテストしてくれます。
ここに記載ありました。
The idiomatic way to bypass test caching is to use -count=1.
go test
のフラグにどんなのがあるのかを調べる
go test って沢山フラグ持っているのですが、それのヘルプは以下で見れます。
$ go help testflag
結構いっぱい出力されるので、パイプでページャ挟んでおいた方が見やすいです。
参考情報
過去の記事については、以下のページからご参照下さい。
- いろいろ備忘録日記まとめ
サンプルコードは、以下の場所で公開しています。
- いろいろ備忘録日記サンプルソース置き場