Open kevinburke opened 5 years ago
Yes, it's the stat
lines. The modification time of the file has changed. The test hash, unlike gobuild
, is not purely content based.
Ah, okay, that's frustrating but fair enough.
Maybe this is worth posting a second ticket about. I have a test that generates configuration files in the testdata
directory. I want to check in the files to Git so that I can see when a change to the code generates a change to the configuration files. The test writes the templates to disk each time, even if the file contents don't change. So even though the contents aren't changing, the mtimes are changing, which means the tests are running every time.
Would it work to walk the file tree and set the mtime of every file after writing it, to a constant value? Alternatively it would be nice to have a hook to say "you can ignore changes to this file when computing the build cache" but maybe that is a Pandora's box we don't want to open.
Can you change the test to write to a temporary file and only update the real file if the temporary file is different? I'm actually not completely confident that that would permit caching, but it might.
In this particular case it turns out the test cache is not being written because there's a file in there with a modification time that is too recent. The file name doesn't print out because the file name prints out after the stat line.
(Please let me know if commenting here is the wrong move, i will create an issue then)
Currently trying to debug why our Go unit tests are not completely cached when retrying a CI pipeline. Stumbled over this issue because i find cache-misses hard to debug as well.
Discoverability of the current debug features could be easily improved by extending some texts. There are some problems related to the documentation:
go help test
i read If a run of go test has any test or non-test flags outside this set, the result is not cached.
. Which is odd because we are using "-vet=off" which is not listed in the strictly cacheable-options. Hence, i am wondering if the listed options needs to be updated, or if they can be auto-generated.I gave GODEBUG=gocachetest=1
a whirl and it seems to me that at least that output is hard to debug:
That is my user experience so far with debugging test cache misses.
So the next thing what i am wondering is i guess why Go files are cached on their content but these used input files are not? I am wondering the same thing as https://github.com/golang/go/issues/35301#issuecomment-548870904 i guess.
Tackling this issue myself now. With the new gocacheprog capability - understanding how tests are cached becomes critical for us.
I think that one thing that can really help is if we can print the full line of testlog/cache data in computeTestInputsID. Currently it only prints it if it's malformed.
I'm trying to figure out why Go is not caching a test I wrote. First, after about 10-15 minutes of searching (including through old issues here) I could not find the flag to enable the debug output that shows you how Go builds its cache. Finally, I found it
(GODEBUG=gocache{hash,test}=1)
I am trying to read through the output of
gocachehash=1
but it's still not easy to figure out what is going wrong. The obvious first thing to do is to run the tests twice and then diff the output and see what's different. However, the output (about 10,000 lines) from two gocachehash runs prints out in different order each time so the diff is very large.Next I tried sorting each output file and printing it. This yields a pretty manageable diff.
I repeated the same exercise with a test that printed out
(cached)
to compare. The cached test diff also hadHASH ... /T/go-build
lines so I assume those are a red herring. That essentially leaves this diff:However I am confused by this one as well because the content hash of the opened file is identical, so I'm not sure why Go is refusing to use the test cache.
Am I correct that these "stat" lines are the reason Go is not caching the result of this test? If so, what is the problem that is leading Go to not cache the results?
Can we build a tool to automate the process of debugging test hashes? E.g. run a test twice, capture the output, sort it, print the lines that differ.