libp2p / go-libp2p-kad-dht

A Kademlia DHT implementation on go-libp2p
https://github.com/libp2p/specs/tree/master/kad-dht
MIT License
516 stars 221 forks source link

fix: garbage collection test race condition #904

Closed dennis-tra closed 9 months ago

dennis-tra commented 9 months ago

Moved ticker initialization outside the garbage collection goroutine. There was a race condition between advancing the mocked time in TestProvidersBackend_GarbageCollection and the initialization of the ticker that triggers the garbage collection runs. It happened that we were advancing the time without the ticker being initialized. Hence, advancing the time hasn't had any effect.

In this PR, I moved the ticker initialization outside the garbage collection goroutine. This means the ticker will be registered with the MockClock object after StartGarbageCollection returns. Calls to mockClock.Add will therefore trigger the ticker.