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

Commit

Permalink
fix(ci): disable preload when NODE_ENV is 'test'
Browse files Browse the repository at this point in the history
Preload tests failed in browser because preload is enabled in browser
context by default and while js-ipfs tests disable preload in tests,
interface-ipfs-core does not.

This means interface-ipfs-core tests triggered dozens of slow/hanging
requests to `nodeX.preload.iofs.io/api/v0/refs` and js-ipfs executed
only 4 at a time. By the time preload tests got executed, the queue was
long and it did not finish before timeout.

This change detects js-ipfs is running in test environment
(`process.env.NODE_ENV === 'test'`) and disables preload by default.

This way we are still be able to test preload by explicitly enabling it
in config, but we won't have preload overhead when running unrelated
interface-ipfs-core tests.

License: MIT
Signed-off-by: Marcin Rataj <lidel@lidel.org>
  • Loading branch information
lidel committed Aug 1, 2019
1 parent 070e205 commit 76ae81c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/cli/commands/daemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ module.exports = {
})
.option('enable-preload', {
type: 'boolean',
default: true
default: process.env.NODE_ENV !== 'test' // preload by default, unless in test env
})
},

Expand Down
5 changes: 4 additions & 1 deletion src/core/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ const configSchema = s({
enabled: 'boolean?',
addresses: optional(s(['multiaddr'])),
interval: 'number?'
}, { enabled: true, interval: 30 * 1000 }),
}, { // defaults if missing:
enabled: process.env.NODE_ENV !== 'test', // preload by default, unless in test env
interval: 30 * 1000
}),
init: optional(union(['boolean', s({
bits: 'number?',
emptyRepo: 'boolean?',
Expand Down
2 changes: 1 addition & 1 deletion src/core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class IPFS extends EventEmitter {
start: true,
EXPERIMENTAL: {},
preload: {
enabled: true,
enabled: process.env.NODE_ENV !== 'test', // preload by default, unless in test env
addresses: [
'/dnsaddr/node0.preload.ipfs.io/https',
'/dnsaddr/node1.preload.ipfs.io/https'
Expand Down

0 comments on commit 76ae81c

Please sign in to comment.