The test flakiness is due to the sync.Pool sometimes forgetting values,
when there is GC pressure. This is part of the stated behaviour of a
pool, I just though this single test would always respond the same way
given the same GOGC. That was, of course, overly optimistic. It shows me
I shouldn't rely on a sync.Pool behaving "simply" even for single
goroutine cases. There's two options:
Only rely on the return value of Put() for tests (though this would
weaken the test a bit).
Use a simpler pool for tests, which doesn't forget values.
The test flakiness is due to the sync.Pool sometimes forgetting values, when there is GC pressure. This is part of the stated behaviour of a pool, I just though this single test would always respond the same way given the same GOGC. That was, of course, overly optimistic. It shows me I shouldn't rely on a
sync.Pool
behaving "simply" even for single goroutine cases. There's two options:I've chosen option #2.