Skip to content

Server graph only #114

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

Merged
merged 2 commits into from
Aug 9, 2018
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
31 changes: 21 additions & 10 deletions bin/serve.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ const OPTS_META = [].concat([{
type: 'string',
alias: ['windowMaxNumber', 'maxNumberOfWindows'],
description: 'Sets maximum number of browser windows the server can keep open at a given time.'
}, {
name: 'graph-only',
type: 'boolean',
alias: ['graphOnly'],
description: 'Launches only the graph component (not thumbnails, dash, etc.) to save memory and reduce the number of processes.'
}, {
name: 'quiet',
type: 'boolean',
Expand Down Expand Up @@ -72,15 +77,14 @@ function main (args) {
console.log(`Spinning up server with pid: ${process.pid}`)
}

app = orca.serve({
port: opts.port,
maxNumberOfWindows: opts.maxNumberOfWindows,
debug: opts.debug,
component: [{
name: 'plotly-graph',
route: '/',
options: plotlyJsOpts
}, {
let component = [{
name: 'plotly-graph',
route: '/',
options: plotlyJsOpts
}]

if (!opts.graphOnly) {
component.push({
name: 'plotly-dashboard',
route: '/dashboard'
}, {
Expand All @@ -98,7 +102,14 @@ function main (args) {
}, {
name: 'plotly-dash-preview',
route: '/dash-preview'
}]
})
}

app = orca.serve({
port: opts.port,
maxNumberOfWindows: opts.maxNumberOfWindows,
debug: opts.debug,
component: component
})

app.on('after-connect', (info) => {
Expand Down
82 changes: 82 additions & 0 deletions test/integration/orca_serve_graph-only_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
const tap = require('tap')
const Application = require('spectron').Application
const request = require('request')

const { paths } = require('../common')
const PORT = 9109
const SERVER_URL = `http://localhost:${PORT}`

const app = new Application({
path: paths.bin,
args: ['serve', '--port', PORT, '--graph-only']
})

tap.tearDown(() => {
if (app && app.isRunning()) {
app.stop()
}
})

tap.test('should launch', t => {
app.start().then(() => {
app.client.getWindowCount().then(cnt => {
// Only one window since only graph component should be running
t.equal(cnt, 1)
t.end()
})
})
})

tap.test('should reply pong to ping POST', t => {
request.post(SERVER_URL + '/ping', (err, res, body) => {
if (err) t.fail(err)

t.equal(res.statusCode, 200, 'code')
t.equal(body, 'pong', 'body')
t.end()
})
})

tap.test('should work for *plotly-graph* component', t => {
request({
method: 'POST',
url: SERVER_URL + '/',
body: JSON.stringify({
figure: {
layout: {
data: [{y: [1, 2, 1]}]
}
}
})
}, (err, res, body) => {
if (err) t.fail(err)

t.equal(res.statusCode, 200, 'code')
t.type(body, 'string')
t.end()
})
})

tap.test('should teardown', t => {
app.stop()
.catch(t.fail)
.then(t.end)
})

tap.test('should not work for *plotly-thumbnail* component', t => {
request({
method: 'POST',
url: SERVER_URL + '/thumbnail',
body: JSON.stringify({
figure: {
layout: {
data: [{y: [1, 2, 1]}]
}
}
})
}, (err, res) => {
t.equal(err.code, 'ECONNREFUSED')
t.equal(res, undefined, 'should be undefined')
t.end()
})
})