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

Commit

Permalink
feat: disable preload by default in test/CI environments
Browse files Browse the repository at this point in the history
resolves #1815

License: MIT
Signed-off-by: Alan Shaw <[email protected]>
  • Loading branch information
Alan Shaw committed Jan 15, 2019
1 parent 6de6adf commit cd1d53a
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
"boom": "^7.2.0",
"bs58": "^4.0.1",
"byteman": "^1.3.5",
"ci-info": "^2.0.0",
"cid-tool": "~0.2.0",
"cids": "~0.5.5",
"class-is": "^1.1.0",
Expand Down
2 changes: 1 addition & 1 deletion src/core/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const schema = Joi.object().keys({
).allow(null),
repoOwner: Joi.boolean().default(true),
preload: Joi.object().keys({
enabled: Joi.boolean().default(true),
enabled: Joi.boolean(),
addresses: Joi.array().items(Joi.multiaddr().options({ convert: false })),
interval: Joi.number().integer().default(30 * 1000)
}).allow(null),
Expand Down
4 changes: 4 additions & 0 deletions src/core/mfs-preload.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
'use strict'

const debug = require('debug')
const { isCI } = require('ci-info')

const log = debug('jsipfs:mfs-preload')
log.error = debug('jsipfs:mfs-preload:error')

module.exports = (self) => {
const options = self._options.preload || {}
options.enabled = options.enabled == null
? !(isCI || process.env.NODE_ENV === 'test')
: Boolean(options.enabled)
options.interval = options.interval || 30 * 1000

if (!options.enabled) {
Expand Down
6 changes: 5 additions & 1 deletion src/core/preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const retry = require('async/retry')
const toUri = require('multiaddr-to-uri')
const debug = require('debug')
const CID = require('cids')
const { isCI } = require('ci-info')
const preload = require('./runtime/preload-nodejs')

const log = debug('jsipfs:preload')
Expand All @@ -14,10 +15,13 @@ const noop = (err) => { if (err) log.error(err) }

module.exports = self => {
const options = self._options.preload || {}
options.enabled = Boolean(options.enabled)
options.enabled = options.enabled == null
? !(isCI || process.env.NODE_ENV === 'test')
: Boolean(options.enabled)
options.addresses = options.addresses || []

if (!options.enabled || !options.addresses.length) {
log('preload disabled')
const api = (_, callback) => {
if (callback) {
setImmediate(() => callback())
Expand Down

0 comments on commit cd1d53a

Please sign in to comment.