Skip to content

cmd/go: invalidate cache entries for test runs using different timeouts #36134

Closed
@bcmills

Description

@bcmills

In the resolution to #22633, we started explicitly ignoring the test timeout when computing its cache key:

case "-test.timeout":
// Special case: this is cacheable but ignored during the hash.
// Do not add to cacheArgs.

The use-case there was to be able to run a set of tests with a short timeout, and then increase that timeout in case of failure without re-running all of the tests.

However, that behavior seems incorrect to me: a test can today vary its behavior based on its timeout by using flag.Lookup("test.timeout") or examining os.Args directly. We have a pretty comprehensive test that checks for cache invalidation for all kinds of esoteric-but-observable behaviors, such as accessing files or environment variables — it's very surprising for one particular input to escape that check.

In #34707 (comment), I even suggested a situation in which a test might want to explicitly vary its behavior based on the timeout: a test using randomized inputs and running with a short timeout might want to check only a few cursory inputs, while a very long (or even unlimited!) timeout might imply a much more exhaustive search.

We do have a tracing hook that checks whether the test happens to observe external environment variables. Something like that might be reasonable for os.Args, but we don't have that today.

I propose that we revert the special case for -test.timeout, and if that proves to be too unpleasant we should add explicit tracking for access to the flag package and/or os.Args so that we only ignore -test.timeout for tests whose behavior verifiably does not depend on the timeout.

CC @jayconrod @rogpeppe @matloob

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions