Open
Description
While investigating a frequent gopls flake (#68659), I encountered several API problems with the countertest
package that make it hard (or really impossible) to use correctly.
I believe the sequence of events that leads to the flake in question are:
TestMain
callscountertest.Open
, because it must be called once during program execution.- The test setup first performs an initial increment of counter values, since we must inc before the first
Read
asReadCounter(counter.New("unknownCounter"))
returns an error rather than succeeding and returning0
. ReadCounter
calls rotate1 internally. I'm not sure why. SinceTestMain
may have occurred ~minutes ago, it's quite likely that the day has actually changed in the meantime, and so the file rotation invalidates the previous counters.
IMO, all three of these are indicative of an API problem:
- We should probably be able to call
countertest.Open
inside each test (albeit not in parallel), to increase test isolation. ReadCounter(counter.New("unknownCounter"))
should return the zero value.ReadCounter
should probably not callrotate1
, but even if it does,countertest
should not be subject to day shifts. We should either stop time, or let thecountertest
user control the progress of time. Otherwise, no test can assert on the output ofRead
.
At the very least, we should fix (3), but it would be good to fix (1) and (2) as well.