Skip to content

Commit

Permalink
Decouple coord package from addressing (#903)
Browse files Browse the repository at this point in the history
* Decouple coord package from addressing

* Go fmt

* fix: garbage collection test race condition (#904)

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.

* Fix test flakes that wait for routing events (#905)

* Increase test iterations to trigger flake

* Add failfast

* Replace routing notification channel with a RoutingNotifier type

* Remove unused code

* Remove test count

---------

Co-authored-by: Dennis Trautwein <[email protected]>
  • Loading branch information
iand and dennis-tra authored Sep 19, 2023
1 parent 156aab2 commit 1220ddd
Show file tree
Hide file tree
Showing 28 changed files with 505 additions and 654 deletions.
2 changes: 1 addition & 1 deletion v2/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func NewBackendPublicKey(ds ds.TxnDatastore, cfg *RecordBackendConfig) (be *Reco
// The values returned from [ProvidersBackend.Fetch] will be of type
// [*providerSet] (unexported). The cfg parameter can be nil, in which case the
// [DefaultProviderBackendConfig] will be used.
func NewBackendProvider(pstore peerstore.Peerstore, dstore ds.Batching, cfg *ProvidersBackendConfig) (be *ProvidersBackend, err error) {
func NewBackendProvider(pstore peerstore.Peerstore, dstore ds.Datastore, cfg *ProvidersBackendConfig) (be *ProvidersBackend, err error) {
if cfg == nil {
if cfg, err = DefaultProviderBackendConfig(); err != nil {
return nil, fmt.Errorf("default provider backend config: %w", err)
Expand Down
7 changes: 4 additions & 3 deletions v2/backend_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,14 +257,15 @@ func (p *ProvidersBackend) StartGarbageCollection() {
p.gcCancel = cancel
p.gcDone = make(chan struct{})

p.log.Info("Provider backend's started garbage collection schedule")
// init ticker outside the goroutine to prevent race condition with
// clock mock in garbage collection test.
ticker := p.cfg.clk.Ticker(p.cfg.GCInterval)

go func() {
defer close(p.gcDone)

ticker := p.cfg.clk.Ticker(p.cfg.GCInterval)
defer ticker.Stop()

p.log.Info("Provider backend started garbage collection schedule")
for {
select {
case <-ctx.Done():
Expand Down
5 changes: 3 additions & 2 deletions v2/backend_provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (

"github.com/benbjohnson/clock"
ds "github.com/ipfs/go-datastore"
syncds "github.com/ipfs/go-datastore/sync"
"github.com/libp2p/go-libp2p"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand All @@ -22,7 +21,9 @@ func newBackendProvider(t testing.TB, cfg *ProvidersBackendConfig) *ProvidersBac
h, err := libp2p.New(libp2p.NoListenAddrs)
require.NoError(t, err)

dstore := syncds.MutexWrap(ds.NewMapDatastore())
dstore, err := InMemoryDatastore()
require.NoError(t, err)

t.Cleanup(func() {
if err = dstore.Close(); err != nil {
t.Logf("closing datastore: %s", err)
Expand Down
39 changes: 0 additions & 39 deletions v2/coord/conversion.go

This file was deleted.

Loading

0 comments on commit 1220ddd

Please sign in to comment.