x/telemetry/counter/countertest: improve ergonomics of countertest.Read #71590
Labels
FeatureRequest
Issues asking for a new feature that does not need a proposal.
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
telemetry
x/telemetry issues
Milestone
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.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:
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.
The text was updated successfully, but these errors were encountered: