Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Commit a869b93

Browse files
committed
chore: address review comments
1 parent 613a9b0 commit a869b93

File tree

4 files changed

+23
-15
lines changed

4 files changed

+23
-15
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@
148148
"multicodec": "~0.5.1",
149149
"multihashes": "~0.4.14",
150150
"multihashing-async": "~0.6.0",
151+
"nanoid": "^2.0.3",
151152
"node-fetch": "^2.3.0",
152153
"p-event": "^4.1.0",
153154
"peer-book": "~0.9.0",

src/core/components/pin/gc-lock.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
const assert = require('assert')
44
const mortice = require('mortice')
5+
const nanoid = require('nanoid')
56
const pull = require('pull-stream/pull')
67
const pullThrough = require('pull-stream/throughs/through')
78
const pullAsyncMap = require('pull-stream/throughs/async-map')
@@ -15,7 +16,7 @@ class GCLock extends EventEmitter {
1516
// Ensure that we get a different mutex for each instance of GCLock
1617
// (There should only be one GCLock instance per IPFS instance, but
1718
// there may be multiple IPFS instances, eg in unit tests)
18-
const randId = (~~(Math.random() * 1e9)).toString(36) + Date.now()
19+
const randId = nanoid()
1920
this.mutex = mortice(randId, {
2021
singleProcess: repoOwner
2122
})

src/core/components/pin/gc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ module.exports = function gc (self) {
2222

2323
self._gcLock.writeLock((lockCb) => {
2424
parallel([
25-
// Get all blocks from the blockstore
25+
// Get all blocks keys from the blockstore
2626
(cb) => self._repo.blocks.query({ keysOnly: true }, cb),
2727
// Mark all blocks that are being used
2828
(cb) => createMarkedSet(self, cb)

test/core/gc.spec.js

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ const dirtyChai = require('dirty-chai')
77
const expect = chai.expect
88
chai.use(dirtyChai)
99

10-
const isNode = require('detect-node')
10+
const IPFSFactory = require('ipfsd-ctl')
1111
const pEvent = require('p-event')
12+
const env = require('ipfs-utils/src/env')
1213
const IPFS = require('../../src/core')
13-
const createTempRepo = require('../utils/create-repo-nodejs')
1414

1515
describe('gc', function () {
1616
const fixtures = [{
@@ -27,28 +27,34 @@ describe('gc', function () {
2727
content: Buffer.from('path4')
2828
}]
2929

30+
let ipfsd
3031
let ipfs
31-
let repo
3232

3333
before(function (done) {
34-
this.timeout(20 * 1000)
35-
repo = createTempRepo()
34+
this.timeout(40 * 1000)
35+
36+
const factory = IPFSFactory.create({ type: 'proc', exec: IPFS })
37+
3638
let config = { Bootstrap: [] }
37-
if (isNode) {
39+
if (env.isNode) {
3840
config.Addresses = {
3941
Swarm: ['/ip4/127.0.0.1/tcp/0']
4042
}
4143
}
42-
ipfs = new IPFS({ repo, config })
43-
ipfs.on('ready', done)
44-
})
4544

46-
after(function (done) {
47-
this.timeout(60 * 1000)
48-
ipfs.stop(done)
45+
factory.spawn({ config }, (err, node) => {
46+
expect(err).to.not.exist()
47+
48+
ipfsd = node
49+
ipfs = ipfsd.api
50+
51+
done()
52+
})
4953
})
5054

51-
after((done) => repo.teardown(done))
55+
after((done) => {
56+
ipfsd.stop(done)
57+
})
5258

5359
const blockAddTests = [{
5460
name: 'add',

0 commit comments

Comments
 (0)