Skip to content

Commit f6befaf

Browse files
authored
removed Startup function from ProviderQueryManager (#741)
* removed Startup function from ProviderQueryManager Now `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 more convenient and reduces the opportunity for a problem if calling `Startup` is missed or if called multiple times. * Remove flaky portion of test - requires synchronization to test sucessive timer delays
1 parent e9446bb commit f6befaf

File tree

6 files changed

+3
-34
lines changed

6 files changed

+3
-34
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`. [#741](https://github.com/ipfs/boxo/pull/741)
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

bitswap/client/internal/session/session_test.go

-16
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,6 @@ func TestSessionFailingToGetFirstBlock(t *testing.T) {
357357
for _, block := range blks {
358358
cids = append(cids, block.Cid())
359359
}
360-
startTick := time.Now()
361360
_, err := session.GetBlocks(ctx, cids)
362361
require.NoError(t, err, "error getting blocks")
363362

@@ -389,7 +388,6 @@ func TestSessionFailingToGetFirstBlock(t *testing.T) {
389388
case <-ctx.Done():
390389
t.Fatal("Did not find more peers")
391390
}
392-
firstTickLength := time.Since(startTick)
393391

394392
// Wait for another broadcast to occur
395393
select {
@@ -402,7 +400,6 @@ func TestSessionFailingToGetFirstBlock(t *testing.T) {
402400
}
403401

404402
// Wait for another broadcast to occur
405-
startTick = time.Now()
406403
select {
407404
case receivedWantReq := <-fpm.wantReqs:
408405
if len(receivedWantReq.cids) < len(cids) {
@@ -412,14 +409,7 @@ func TestSessionFailingToGetFirstBlock(t *testing.T) {
412409
t.Fatal("Never rebroadcast want list")
413410
}
414411

415-
// Tick should take longer
416-
consecutiveTickLength := time.Since(startTick)
417-
if firstTickLength > consecutiveTickLength {
418-
t.Fatal("Should have increased tick length after first consecutive tick")
419-
}
420-
421412
// Wait for another broadcast to occur
422-
startTick = time.Now()
423413
select {
424414
case receivedWantReq := <-fpm.wantReqs:
425415
if len(receivedWantReq.cids) < len(cids) {
@@ -429,12 +419,6 @@ func TestSessionFailingToGetFirstBlock(t *testing.T) {
429419
t.Fatal("Never rebroadcast want list")
430420
}
431421

432-
// Tick should take longer
433-
secondConsecutiveTickLength := time.Since(startTick)
434-
if consecutiveTickLength > secondConsecutiveTickLength {
435-
t.Fatal("Should have increased tick length after first consecutive tick")
436-
}
437-
438422
// Should not have tried to find peers on consecutive ticks
439423
select {
440424
case <-fpf.findMorePeersRequested:

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)