Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added go -> js extract tests #208

Merged
merged 1 commit into from
Jan 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions runner/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
5 changes: 4 additions & 1 deletion tests/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
45 changes: 45 additions & 0 deletions tests/extract-go2.js
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 1 addition & 1 deletion tests/extract-js2.go.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
7 changes: 7 additions & 0 deletions tests/lib/create-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -112,6 +118,7 @@ const CreateGo = async (config, init, IPFS, count) => {
console.log('Daemon is ready')
})
await once(peer, 'done')

return peer
}

Expand Down
2 changes: 1 addition & 1 deletion tests/local-add.go.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down