Skip to content

Commit f8419fb

Browse files
committed
removed Startup function from ProviderQueryManager
The `providerquerymanager.New` creates a `ProvicerQueryManager` that is already started. There is no use case for starting PQM at a later time than it is created. Removing the need to call a `Statup` function separately from `New` is less convenient and can be a problem if this step is missed or if called multiple times.
1 parent e9446bb commit f8419fb

File tree

5 files changed

+3
-18
lines changed

5 files changed

+3
-18
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ The following emojis are used to highlight certain changes:
6767
- `routing/http/server`: exposes Prometheus metrics on `prometheus.DefaultRegisterer` and a custom one can be provided via `WithPrometheusRegistry` [#722](https://github.com/ipfs/boxo/pull/722)
6868
- `gateway`: `NewCacheBlockStore` and `NewCarBackend` will use `prometheus.DefaultRegisterer` when a custom one is not specified via `WithPrometheusRegistry` [#722](https://github.com/ipfs/boxo/pull/722)
6969
- `filestore`: added opt-in `WithMMapReader` option to `FileManager` to enable memory-mapped file reads [#665](https://github.com/ipfs/boxo/pull/665)
70+
- `bitswap/routing` `ProviderQueryManager` does not require calling `Startup` separate from `New`.
7071

7172
### Changed
7273

bitswap/client/bitswap_with_sessions_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@ func TestCustomProviderQueryManager(t *testing.T) {
134134
if err != nil {
135135
t.Fatal(err)
136136
}
137-
pqm.Startup()
138137
bs := bitswap.New(ctx, a.Adapter, pqm, a.Blockstore,
139138
bitswap.WithClientOption(client.WithDefaultProviderQueryManager(false)))
140139
a.Exchange.Close() // close old to be sure.

bitswap/client/client.go

-1
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,6 @@ func New(parent context.Context, network bsnet.BitSwapNetwork, providerFinder Pr
190190
// Should not be possible to hit this
191191
panic(err)
192192
}
193-
pqm.Startup()
194193
bs.pqm = pqm
195194
}
196195

routing/providerquerymanager/providerquerymanager.go

+2-5
Original file line numberDiff line numberDiff line change
@@ -150,12 +150,9 @@ func New(ctx context.Context, dialer ProviderQueryDialer, router ProviderQueryRo
150150
}
151151
}
152152

153-
return pqm, nil
154-
}
155-
156-
// Startup starts processing for the ProviderQueryManager.
157-
func (pqm *ProviderQueryManager) Startup() {
158153
go pqm.run()
154+
155+
return pqm, nil
159156
}
160157

161158
type inProgressRequest struct {

routing/providerquerymanager/providerquerymanager_test.go

-11
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ func TestNormalSimultaneousFetch(t *testing.T) {
7676
}
7777
ctx := context.Background()
7878
providerQueryManager := mustNotErr(New(ctx, fpd, fpn))
79-
providerQueryManager.Startup()
8079
keys := random.Cids(2)
8180

8281
sessionCtx, cancel := context.WithTimeout(ctx, 5*time.Second)
@@ -114,7 +113,6 @@ func TestDedupingProviderRequests(t *testing.T) {
114113
}
115114
ctx := context.Background()
116115
providerQueryManager := mustNotErr(New(ctx, fpd, fpn))
117-
providerQueryManager.Startup()
118116
key := random.Cids(1)[0]
119117

120118
sessionCtx, cancel := context.WithTimeout(ctx, 5*time.Second)
@@ -155,7 +153,6 @@ func TestCancelOneRequestDoesNotTerminateAnother(t *testing.T) {
155153
}
156154
ctx := context.Background()
157155
providerQueryManager := mustNotErr(New(ctx, fpd, fpn))
158-
providerQueryManager.Startup()
159156

160157
key := random.Cids(1)[0]
161158

@@ -202,7 +199,6 @@ func TestCancelManagerExitsGracefully(t *testing.T) {
202199
managerCtx, managerCancel := context.WithTimeout(ctx, 5*time.Millisecond)
203200
defer managerCancel()
204201
providerQueryManager := mustNotErr(New(managerCtx, fpd, fpn))
205-
providerQueryManager.Startup()
206202

207203
key := random.Cids(1)[0]
208204

@@ -238,7 +234,6 @@ func TestPeersWithConnectionErrorsNotAddedToPeerList(t *testing.T) {
238234
}
239235
ctx := context.Background()
240236
providerQueryManager := mustNotErr(New(ctx, fpd, fpn))
241-
providerQueryManager.Startup()
242237

243238
key := random.Cids(1)[0]
244239

@@ -275,7 +270,6 @@ func TestRateLimitingRequests(t *testing.T) {
275270
ctx, cancel := context.WithCancel(ctx)
276271
defer cancel()
277272
providerQueryManager := mustNotErr(New(ctx, fpd, fpn, WithMaxInProcessRequests(maxInProcessRequests)))
278-
providerQueryManager.Startup()
279273

280274
keys := random.Cids(maxInProcessRequests + 1)
281275
sessionCtx, cancel := context.WithTimeout(ctx, 5*time.Second)
@@ -317,7 +311,6 @@ func TestUnlimitedRequests(t *testing.T) {
317311
ctx, cancel := context.WithCancel(ctx)
318312
defer cancel()
319313
providerQueryManager := mustNotErr(New(ctx, fpd, fpn, WithMaxInProcessRequests(0)))
320-
providerQueryManager.Startup()
321314

322315
keys := random.Cids(inProcessRequests)
323316
sessionCtx, cancel := context.WithTimeout(ctx, 5*time.Second)
@@ -355,7 +348,6 @@ func TestFindProviderTimeout(t *testing.T) {
355348
}
356349
ctx := context.Background()
357350
providerQueryManager := mustNotErr(New(ctx, fpd, fpn, WithMaxTimeout(2*time.Millisecond)))
358-
providerQueryManager.Startup()
359351
keys := random.Cids(1)
360352

361353
sessionCtx, cancel := context.WithTimeout(ctx, 5*time.Second)
@@ -379,7 +371,6 @@ func TestFindProviderPreCanceled(t *testing.T) {
379371
}
380372
ctx := context.Background()
381373
providerQueryManager := mustNotErr(New(ctx, fpd, fpn, WithMaxTimeout(100*time.Millisecond)))
382-
providerQueryManager.Startup()
383374
keys := random.Cids(1)
384375

385376
sessionCtx, cancel := context.WithCancel(ctx)
@@ -404,7 +395,6 @@ func TestCancelFindProvidersAfterCompletion(t *testing.T) {
404395
}
405396
ctx := context.Background()
406397
providerQueryManager := mustNotErr(New(ctx, fpd, fpn, WithMaxTimeout(100*time.Millisecond)))
407-
providerQueryManager.Startup()
408398
keys := random.Cids(1)
409399

410400
sessionCtx, cancel := context.WithCancel(ctx)
@@ -437,7 +427,6 @@ func TestLimitedProviders(t *testing.T) {
437427
}
438428
ctx := context.Background()
439429
providerQueryManager := mustNotErr(New(ctx, fpd, fpn, WithMaxProviders(max), WithMaxTimeout(100*time.Millisecond)))
440-
providerQueryManager.Startup()
441430
keys := random.Cids(1)
442431

443432
providersChan := providerQueryManager.FindProvidersAsync(ctx, keys[0], 0)

0 commit comments

Comments
 (0)