Repository navigation
Fix test failures on MacOS: symlink expansion, check err, download problems - #140
Conversation
4a3a2e3 to
e824cb3
Compare
9a54eaf to
e30d76c
Compare
37f30df to
555ff78
Compare
tannerjfco
left a comment
There was a problem hiding this comment.
I've run this several times on my mac and ubuntu machines, both seem to be passing consistently with this changes. Thanks for spending the time to track these problems down.
| // This wrapper function can prevent problems with docker-for-mac trying to use /var/..., which is not typically | ||
| // shared/mounted. It will be expanded via the /var symlink to /private/var/... | ||
| func OsTempDir() (string, error) { | ||
| dirName := os.TempDir() |
There was a problem hiding this comment.
Since we had issues w/ previous test runs, do we need to use RandString to add some entropy to these directory names by default?
I realize we added the prefix argument to CreateTmpDir, but since those are static values which are the same on every test run is that actually enough?
There was a problem hiding this comment.
OsTempDir() is only used to get the actual normalized $TMPDIR; getting unique names inside it is handled tin testcommon.CreateTmpDir(). It's guaranteed to get a unique dir that nobody will fight over. We just need to use it everywhere. (or ioutil.TempDir() where we aren't worried about the docker mounting).
| testDir := CreateTmpDir(site.Name) | ||
| site.Dir = testDir | ||
| fmt.Printf("Prepping test for %s.", site.Name) | ||
| log.Printf("Prepping test for %s.\n", site.Name) |
There was a problem hiding this comment.
Can we make all of these a log.Debug or log.Info? I think I'm mostly in favor of keeping tests quiet unless we specifically need to enable output for some reason. Especially on stuff like this that should work 99.99% of the time.
There was a problem hiding this comment.
Changed to logrus, updated as necessary.
| }) | ||
| if err != nil { | ||
| log.Printf("Tar extraction failed err=%v ", err) | ||
| _, _ = system.RunCommand("cp", []string{tarballPath, "/tmp/"}) |
There was a problem hiding this comment.
Should we do this copy in golang instead of shelling out? It's more work, but it seems like we've been moving away from shelling out.
There was a problem hiding this comment.
I think we might be able to delete this line now. Shelling out for a test-only situation that's only intended for preserving some artifact is probably not so bad. But I think it can just be removed.
|
|
||
| // Create a testsite and ensure the prepare() method extracts files into a temporary directory. | ||
| ts.Prepare() | ||
| err = ts.Prepare() |
There was a problem hiding this comment.
Probably outside of the scope of fixing here, just want to comment to tag this: I'm betting this change needs to be made elsewhere as well. Test code has a nasty habit of getting copy+pasted around.
There was a problem hiding this comment.
I grepped for instances of this particular problem and found none, but really want to get some tools in there that will catch this kind of thing.
beeradb
left a comment
There was a problem hiding this comment.
I have some minor feedback but all of it is optional. Thanks for getting this fixed!
Also minor change to Makefile to make it easy to run a single test
555ff78 to
b81b085
Compare
|
Added this post-mortem to the OP: Post-Mortem of this issue: Serious race condition in testsI really had to completely understand how we got corrupted downloads in our tests so spent some time on it last night. From Lesser-Known Features of Go Test:
Now for some of the simpler things:
|
|
Great work. Awesome write-up. So sorry for your pain 😢 |
The Problem:
On MacOS tests are failing related to the excellent new testcommon library.
The Fix:
make testcmdandmake testpkgso they can be run separately.make test TESTARGS="-run TestValidTestSite"for exampleThe Test:
CGO_ENABLED=0 go test -v -installsuffix 'static' -ldflags "-extldflags -static" ./pkg/... -run TestValidTestSiteWithout this PR you should see many ugly failures (maybe 50% of the time). With it you should get consistent results.
make testAutomation Overview:
No new tests were introduced, but some changes were made to existing test infrastructure, including expanding symlinks in temp dir creation.
Related Issue Link(s):
Release/Deployment notes:
Post-Mortem of this issue: Serious race condition in tests
I really had to completely understand how we got corrupted downloads in our tests so spent some time on it last night.
From Lesser-Known Features of Go Test:
make pkg). Per the above, that means we can have more than one test going at a time.CGO_ENABLED=0 go test -v -installsuffix 'static' -ldflags "-extldflags -static" ./pkg/... -run TestValidTestSite, and I saw intermittent failures, even though I thought I was explicitly running one test. What I saw was a corrupted tarball after download nearly half the runs.Now for some of the simpler things: