-
Notifications
You must be signed in to change notification settings - Fork 18.3k
Description
Abstract
Add go test -long
as a gate for (very) long tests.
Problem statement
I write MetalLB, a set of Go programs that deploy into Kubernetes and do marginally useful things within. Currently, it's tested entirely by short and fast unit tests, but I would very much like to add integration tests that run the code against Kubernetes.
This involves spinning up a local Kubernetes cluster, which takes several minutes, and building and pushing several Docker images, taking another minute or so. This means these tests take 2-5 minutes to even start running, and probably another minute or two to finish.
With the current Go tool UX, the default behavior is the opposite of desirable for rapid iteration, and I often find myself accidentally spinning up this giant coal plant of a test during iterative development. This is an irritating series of little paper cuts.
Empirically, people are solving this on their own. In my code I check for a "RUN_SLOW_TESTS" env var, and use that to t.Skip
the long tests. It works well enough, but everyone implementing their own hacks for this means the developer experience is fragmented, and it's easier to miss the fact that long tests exist at all, because the "run absolutely everything" switch is different for everyone.
Proposal
In a perfect world, remove go test -short
and replace it with go test -long
, flipping the default to be "you must choose to run the very slow things. Given that this breaking change is likely not palatable, I propose adding go test -long
in addition to the existing go test -short
.
In effect, this creates 3 bands of tests: short, medium, and long, with "short and medium" being the default go test
runs. -short
and -long
act as lowering or raising a bar of "how much I'm willing to wait": -short
only allows the short band to run, whereas -long
allows short, medium and long to run.
Again I'm not in love with the 3 bands and would prefer 2 with a flipped default. Given that there would be three, I'd propose the following rules of thumb for what tests go where:
go test -short
should be as fast as the compiler, fast enough that I can run compile+test interactively as part of an IDE.go test
should be fast enough that the developer's attention doesn't wander off to Twitter. Call it less than 10s total.go test -long
is for persnickety CI pipelines and coffee breaks. Minutes, tens of minute, hours if you really must (though I sincerely hope nobody does that last one).
cc @bradfitz