Skip to content

Commit d8febb9

Browse files
HDegrootemafintosh
andauthored
Don't start downloading when core is not active (#477)
* Don't start downloading when core is not active * we can simplify --------- Co-authored-by: Mathias Buus <[email protected]>
1 parent 89b6dc6 commit d8febb9

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

lib/replicator.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1236,7 +1236,7 @@ module.exports = class Replicator {
12361236
this.peers = []
12371237
this.findingPeers = 0 // updateable from the outside
12381238
this.destroyed = false
1239-
this.downloading = true
1239+
this.downloading = false
12401240
this.activeSessions = 0
12411241

12421242
this._attached = new Set()

test/replicate.js

+22
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const test = require('brittle')
22
const b4a = require('b4a')
3+
const RAM = require('random-access-memory')
34
const NoiseSecretStream = require('@hyperswarm/secret-stream')
45
const { create, replicate, unreplicate, eventFlush } = require('./helpers')
56
const { makeStreamPair } = require('./helpers/networking.js')
@@ -24,6 +25,27 @@ test('basic replication', async function (t) {
2425
t.is(d, 5)
2526
})
2627

28+
test('basic downloading is set immediately after ready', function (t) {
29+
t.plan(2)
30+
31+
const a = new Hypercore(RAM)
32+
33+
a.on('ready', function () {
34+
t.ok(a.replicator.downloading)
35+
})
36+
37+
const b = new Hypercore(RAM, { active: false })
38+
39+
b.on('ready', function () {
40+
t.absent(b.replicator.downloading)
41+
})
42+
43+
t.teardown(async () => {
44+
await a.close()
45+
await b.close()
46+
})
47+
})
48+
2749
test('basic replication from fork', async function (t) {
2850
const a = await create()
2951

0 commit comments

Comments
 (0)