From 6291c9ac7ff20ab8de333f3a0c66c95dd2f4d48a Mon Sep 17 00:00:00 2001 From: ron litzenberger Date: Thu, 24 Jan 2019 10:14:56 -0600 Subject: [PATCH] added go -> js extract tests --- runner/config.js | 4 ++++ tests/config/index.js | 5 ++++- tests/extract-go2.js | 45 ++++++++++++++++++++++++++++++++++++++++ tests/extract-js2.go.js | 2 +- tests/lib/create-node.js | 7 +++++++ tests/local-add.go.js | 2 +- 6 files changed, 62 insertions(+), 3 deletions(-) create mode 100644 tests/extract-go2.js diff --git a/runner/config.js b/runner/config.js index df521038..d310b29c 100644 --- a/runner/config.js +++ b/runner/config.js @@ -143,6 +143,10 @@ const testAbstracts = [ name: 'extractJs2Go', file: 'extract-js2.go.js' }, + { + name: 'extractGo2Js', + file: 'extract-go2.js' + }, { name: 'peerTransferBrowser', file: 'peer-transfer.browser.js' diff --git a/tests/config/index.js b/tests/config/index.js index c881a8b7..e3cd7d28 100644 --- a/tests/config/index.js +++ b/tests/config/index.js @@ -39,7 +39,10 @@ const tests = { 'unixFsAdd': [{ 'fileSet': ['OneKBFile', 'OneMBFile', 'One4MBFile', 'One64MBFile'] } ], 'extractJs2Go': [{ 'warmup': 'Off', - 'fileSet': ['OneKBFile', 'OneMBFile', 'One64MBFile', 'one512mbfile'] } ] + 'fileSet': ['OneKBFile', 'OneMBFile', 'One4MBFile', 'One64MBFile'] } ], +'extractGo2Js': [{ + 'warmup': 'Off', + 'fileSet': ['OneKBFile', 'OneMBFile', 'One4MBFile', 'One64MBFile'] } ] } const config = { diff --git a/tests/extract-go2.js b/tests/extract-go2.js new file mode 100644 index 00000000..f25547d4 --- /dev/null +++ b/tests/extract-go2.js @@ -0,0 +1,45 @@ +'use strict' + +const os = require('os') +const fs = require('fs') +const { build } = require('./schema/results') +const { file } = require('./lib/fixtures') +const run = require('./lib/runner') +const { once } = require('stream-iterators-utils') +const NodeFactory = require('./lib/node-factory') +const util = require('util') +const execute = util.promisify(util.promisify(require('child_process').exec)) +const conf = { tmpPath: os.tmpdir() } + +async function extractGo2Js (ipfs, name, warmup, fileSet, version) { + //Runner rtunrs the NodeJS ipfs but we need to create the Go ipfs + const nodeFactory = new NodeFactory() + await nodeFactory.add('go') + const filePath = await file(fileSet) + const peer = ipfs[0] + + const peerId = await peer.id() + let command = `export IPFS_PATH=${conf.tmpPath}/ipfs0 && ipfs swarm connect ${peerId.addresses[0]} > /dev/null` + await execute(command) + // redirect stderr to dev/null due to the progress of file being processed is sent to stderr causing maxBuffer error + const addCommand = `export IPFS_PATH=${conf.tmpPath}/ipfs0 && ipfs add ${filePath} 2> /dev/null` + const { stdout } = await execute(addCommand) + const start = process.hrtime() + let stream = peer.catReadableStream(stdout.split(' ')[1]) + // endof steam + stream.resume() + await once(stream, 'end') + const end = process.hrtime(start) + await nodeFactory.stop('go') + return build({ + name: name, + warmup: warmup, + file: filePath, + meta: { version: version }, + description: 'Extract files from GO to JS IPFS peers', + file_set: fileSet, + duration: { s: end[0], + ms: end[1] / 1000000 } + }) +} +run(extractGo2Js) diff --git a/tests/extract-js2.go.js b/tests/extract-js2.go.js index 09a3f48c..65c9503c 100644 --- a/tests/extract-js2.go.js +++ b/tests/extract-js2.go.js @@ -26,7 +26,7 @@ async function extractJs2Go (ipfs, name, warmup, fileSet, version) { await execute(command) const start = process.hrtime() - command = `export IPFS_PATH=${conf.tmpPath}/ipfs0 && ipfs cat ${inserted[0].hash} > /dev/null` + command = `export IPFS_PATH=${conf.tmpPath}/ipfs0 && ipfs cat ${inserted[0].hash} > /dev/null` await execute(command) const end = process.hrtime(start) await nodeFactory.stop('go') diff --git a/tests/lib/create-node.js b/tests/lib/create-node.js index f38ed77b..9ba819a7 100644 --- a/tests/lib/create-node.js +++ b/tests/lib/create-node.js @@ -82,8 +82,14 @@ const CreateGo = async (config, init, IPFS, count) => { await fsWriteFile(`${peerDir}/config`, JSON.stringify(peerConf)) let peer = spawn('ipfs', ['daemon'], { env: Object.assign(process.env, { IPFS_PATH: peerDir }) }) peer.version = function () { return '1' } + peer.addresses = '' peer.stdout.on('data', (data) => { let version = {} + const addresses = [] + if (data.includes('Swarm announcing')) { + addresses.push(data.toString('utf8').split('Swarm announcing')[1]) + peer.addresses = addresses + } if (data.includes('go-ipfs version:')) { const stdArray = data.toString('utf8').split('\n') for (let item of stdArray) { @@ -112,6 +118,7 @@ const CreateGo = async (config, init, IPFS, count) => { console.log('Daemon is ready') }) await once(peer, 'done') + return peer } diff --git a/tests/local-add.go.js b/tests/local-add.go.js index 315fbee3..393ac7ac 100644 --- a/tests/local-add.go.js +++ b/tests/local-add.go.js @@ -11,7 +11,7 @@ const conf = { tmpPath: os.tmpdir() } const unixFsAddGo = async (node, name, warmup, fileSet, version) => { const filePath = await file(fileSet) const start = process.hrtime() - let command = `export IPFS_PATH=${conf.tmpPath}/ipfs0 && ipfs add ${filePath}` + let command = `export IPFS_PATH=${conf.tmpPath}/ipfs0 && ipfs add ${filePath} > /dev/null` await execute(command) const end = process.hrtime(start) return build({