Skip to content

Commit 120d1c7

Browse files
authored
fix: really remove node globals (#219)
* fix: really remove node globals * fix: fix scheduleProcessTasks * fix: bump varint * fix: bump varint
1 parent 6a4e512 commit 120d1c7

File tree

4 files changed

+13
-9
lines changed

4 files changed

+13
-9
lines changed

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,13 @@
4646
"aegir": "^21.9.0",
4747
"async-iterator-all": "^1.0.0",
4848
"benchmark": "^2.1.4",
49+
"buffer": "^5.6.0",
4950
"chai": "^4.2.0",
5051
"delay": "^4.3.0",
5152
"dirty-chai": "^2.0.1",
5253
"ipfs-repo": "^2.0.0",
54+
"ipfs-utils": "^2.2.0",
55+
"iso-random-stream": "^1.1.1",
5356
"libp2p": "^0.27.0",
5457
"libp2p-kad-dht": "^0.18.3",
5558
"libp2p-mplex": "^0.9.2",
@@ -68,7 +71,6 @@
6871
"peer-info": "^0.17.0",
6972
"promisify-es6": "^1.0.3",
7073
"rimraf": "^3.0.0",
71-
"buffer": "^5.6.0",
7274
"stats-lite": "^2.2.0",
7375
"uuid": "^3.3.2"
7476
},
@@ -85,7 +87,7 @@
8587
"multihashing-async": "^0.8.0",
8688
"protons": "^1.0.1",
8789
"streaming-iterables": "^4.1.1",
88-
"varint-decoder": "~0.1.1"
90+
"varint-decoder": "^0.4.0"
8991
},
9092
"pre-push": [
9193
"lint",

src/decision-engine/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ class DecisionEngine {
5050
}
5151

5252
_scheduleProcessTasks () {
53-
setImmediate(() => this._processTasks())
53+
setTimeout(() => {
54+
this._processTasks()
55+
})
5456
}
5557

5658
// Pull tasks off the request queue and send a message to the corresponding

test/utils/make-block.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
const multihashing = require('multihashing-async')
44
const CID = require('cids')
55
const Block = require('ipld-block')
6-
const crypto = require('crypto')
6+
const randomBytes = require('iso-random-stream/src/random')
77
const range = require('lodash.range')
88
const { Buffer } = require('buffer')
99
const uuid = require('uuid/v4')
1010

1111
module.exports = async (count, size) => {
1212
const blocks = await Promise.all(
1313
range(count || 1).map(async () => {
14-
const data = size ? crypto.randomBytes(size) : Buffer.from(`hello world ${uuid()}`)
14+
const data = size ? randomBytes(size) : Buffer.from(`hello world ${uuid()}`)
1515
const hash = await multihashing(data, 'sha2-256')
1616
return new Block(data, new CID(hash))
1717
})

test/utils/mocks.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const PeerId = require('peer-id')
55
const PeerInfo = require('peer-info')
66
const PeerStore = require('libp2p/src/peer-store')
77
const Node = require('./create-libp2p-node').bundle
8-
const os = require('os')
8+
const tmpdir = require('ipfs-utils/src/temp-dir')
99
const Repo = require('ipfs-repo')
1010
const EventEmitter = require('events')
1111

@@ -59,14 +59,14 @@ exports.mockNetwork = (calls, done, onMsg) => {
5959
messages,
6060
connects,
6161
connectTo (p) {
62-
setImmediate(() => {
62+
setTimeout(() => {
6363
connects.push(p)
6464
})
6565
},
6666
sendMessage (p, msg) {
6767
messages.push([p, msg])
6868

69-
setImmediate(() => {
69+
setTimeout(() => {
7070
finish([p, msg])
7171
})
7272

@@ -182,7 +182,7 @@ exports.genBitswapNetwork = async (n, enableDHT = false) => {
182182
})
183183

184184
// create the repos
185-
const tmpDir = os.tmpdir()
185+
const tmpDir = tmpdir()
186186
netArray.forEach((net, i) => {
187187
const repoPath = tmpDir + '/' + net.peerInfo.id.toB58String()
188188
net.repo = new Repo(repoPath)

0 commit comments

Comments
 (0)