diff --git a/test/cli/daemon.js b/test/cli/daemon.js index 2a94508b6c..4e284656f8 100644 --- a/test/cli/daemon.js +++ b/test/cli/daemon.js @@ -7,8 +7,9 @@ const ipfsCmd = require('../utils/ipfs-exec') const pull = require('pull-stream') const toPull = require('stream-to-pull-stream') const os = require('os') -const fs = require('fs') const path = require('path') +const hat = require('hat') +const fs = require('fs') const isWindows = os.platform() === 'win32' @@ -65,7 +66,7 @@ describe('daemon', () => { let ipfs beforeEach(() => { - repoPath = '/tmp/ipfs-test-not-found-' + Math.random().toString().substring(2, 8) + repoPath = path.join(os.tmpdir(), 'ipfs-test-not-found-' + hat()) ipfs = ipfsCmd(repoPath) }) diff --git a/test/core/bitswap.spec.js b/test/core/bitswap.spec.js index f9ebe844fe..4aea3ece88 100644 --- a/test/core/bitswap.spec.js +++ b/test/core/bitswap.spec.js @@ -111,7 +111,7 @@ describe('bitswap', function () { afterEach(function (done) { this.timeout(60 * 1000) - inProcNode.stop(() => done()) + setTimeout(() => inProcNode.stop(() => done()), 500) }) describe('transfer a block between', () => { diff --git a/test/core/create-node.spec.js b/test/core/create-node.spec.js index 011c1b7a78..03d941ee35 100644 --- a/test/core/create-node.spec.js +++ b/test/core/create-node.spec.js @@ -7,6 +7,9 @@ const dirtyChai = require('dirty-chai') const expect = chai.expect chai.use(dirtyChai) const series = require('async/series') +const os = require('os') +const path = require('path') +const hat = require('hat') const isNode = require('detect-node') const IPFS = require('../../src/core') @@ -19,7 +22,7 @@ describe('create node', function () { this.timeout(80 * 1000) const node = new IPFS({ - repo: '/tmp/ipfs-repo-' + Math.random(), + repo: path.join(os.tmpdir(), 'ipfs-repo-' + hat()), config: { Addresses: { Swarm: [] diff --git a/test/interop/repo.js b/test/interop/repo.js index b82ce74804..83ebac02dc 100644 --- a/test/interop/repo.js +++ b/test/interop/repo.js @@ -8,6 +8,8 @@ chai.use(dirtyChai) const waterfall = require('async/waterfall') const crypto = require('crypto') const os = require('os') +const path = require('path') +const hat = require('hat') const GoDaemon = require('../utils/interop-daemon-spawner/go') const JsDaemon = require('../utils/interop-daemon-spawner/js') @@ -22,7 +24,7 @@ function catAndCheck (daemon, hash, data, callback) { describe('repo', () => { it('read repo: go -> js', (done) => { - const dir = os.tmpdir() + '/' + Math.ceil(Math.random() * 10000) + const dir = path.join(os.tmpdir(), hat()) const data = crypto.randomBytes(1024 * 5) const goDaemon = new GoDaemon({ @@ -57,7 +59,7 @@ describe('repo', () => { // This was last due to an update on go-ipfs that changed how datastore is // configured it.skip('read repo: js -> go', (done) => { - const dir = os.tmpdir() + '/' + Math.ceil(Math.random() * 10000) + const dir = path.join(os.tmpdir(), hat()) const data = crypto.randomBytes(1024 * 5) const jsDaemon = new JsDaemon({init: true, disposable: false, path: dir}) diff --git a/test/utils/interop-daemon-spawner/util.js b/test/utils/interop-daemon-spawner/util.js index c0ca77a338..7ec425be99 100644 --- a/test/utils/interop-daemon-spawner/util.js +++ b/test/utils/interop-daemon-spawner/util.js @@ -3,11 +3,12 @@ const os = require('os') const crypto = require('libp2p-crypto') const path = require('path') +const hat = require('hat') exports.tmpDir = (prefix) => { return path.join( os.tmpdir(), prefix || 'js-ipfs-interop', - crypto.randomBytes(32).toString('hex') + hat() ) } diff --git a/test/utils/ipfs-factory-instance/index.js b/test/utils/ipfs-factory-instance/index.js index febc85ca86..568a1710a7 100644 --- a/test/utils/ipfs-factory-instance/index.js +++ b/test/utils/ipfs-factory-instance/index.js @@ -3,6 +3,8 @@ const series = require('async/series') const each = require('async/each') const hat = require('hat') +const os = require('os') +const path = require('path') const defaultConfig = require('./default-config.json') const IPFS = require('../../../src/core') @@ -30,7 +32,7 @@ function Factory () { } if (!repoPath) { - repoPath = '/tmp/.ipfs-' + hat() + repoPath = path.join(os.tmpdir(), '.ipfs-' + hat()) } const config = Object.assign({}, defaultConfig, suppliedConfig)