Skip to content

Instantly share code, notes, and snippets.

@bweis
Created July 19, 2017 19:41
Show Gist options
  • Save bweis/5b65b7678f3a707e9a4682fdc2f2a1a3 to your computer and use it in GitHub Desktop.
Save bweis/5b65b7678f3a707e9a4682fdc2f2a1a3 to your computer and use it in GitHub Desktop.
'use strict'
const autocannon = require('autocannon');
let jsf = require('json-schema-faker');
let schema = {
type: 'object',
properties: {
id: -1,
Info: {
foo: 'bar',
zap: 'zah',
Address: {
name: 'James',
street: 'Spear Street',
number: '125',
city: 'San Fransisco'
},
Dog: {
type: 'string',
chance: {
weighted: [
['poodle', 'Golden Retreiver', 'Black Lab'],
[1, 1, 3]
]
}
}
},
John: {
First: 'John',
Last: {
type: 'string',
chance: {'last': {}}
},
Friends: {
type: 'array',
minItems: 2,
maxItems: 5,
items: {
First: {
type: 'string',
chance: {'first': {}}
},
Last: {
type: 'string',
chance: {'last': {}}
},
Age: 52
}
}
}
},
required: ['id', 'Info', 'John'],
};
const instance = autocannon({
headers: {
'Authorization': 'Bearer ####',
'Content-Type': 'application/json'
},
url: 'https://ingestion-iog7rg5sc3lf.dev.sfdc-matrix.net/streams/teju_endpoint001/teju_ic001/event',
body: JSON.stringify(schema),
method: 'POST',
pipelining: 50,
duration: 300,
overallRate: 50000,
connections: 1000,
// setupClient: setupClient
}, (err, result) => handleResults(result));
// results passed to the callback are the same as those emitted from the done events
instance.on('done', handleResults)
instance.on('response', handleResponse)
function handleResponse(client, statusCode, resBytes, responseTime) {
client.setBody(JSON.stringify(jsf(schema)));
}
function handleResults(result) {
console.log(result);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment