-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #76 from fed135/next
[Release] v1.12.2
- Loading branch information
Showing
4 changed files
with
137 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
function simulateNetwork() { | ||
let tick = 0; | ||
while(true) { | ||
if (++tick > 0xffff) break; | ||
} | ||
return true; | ||
} | ||
|
||
function calculateResponseTime(numItems) { | ||
return Math.round(30 + numItems * 0.5); | ||
} | ||
|
||
function getAssets(ids, { language }) { | ||
return new Promise((resolve, reject) => { | ||
simulateNetwork(); | ||
setTimeout(() => resolve(ids.map(id => ({ id, language }))), calculateResponseTime(ids.length)); | ||
}); | ||
} | ||
|
||
function getErroredRequest(ids, { language }) { | ||
return new Promise((resolve, reject) => { | ||
throw new Error('Something went wrong'); | ||
}); | ||
} | ||
|
||
module.exports = { | ||
getAssets, | ||
getErroredRequest, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,24 @@ | ||
const {getAssets} = require('../integration/utils/dao.js'); | ||
const {getAssets} = require('./dao.js'); | ||
|
||
module.exports = { | ||
test: { | ||
testDuration: 60000, | ||
testDuration: 1000, | ||
requestDelay: 0, | ||
languages: ['fr', 'en', 'pr', 'it', 'ge'] | ||
languages: ['fr', 'en', 'ge', 'it', 'pr'], | ||
}, | ||
setup: { | ||
resolver: getAssets, | ||
uniqueParams: ['language'], | ||
cache: { limit: 60000, steps: 5, base: 5000 }, | ||
batch: { tick: 2, limit: 50 }, | ||
batch: { tick: 10, max: 50 }, | ||
retry: { base: 1, step: 2 }, | ||
}, | ||
assert: { | ||
completed: [30000, 100000], | ||
cacheHits: [1000, 4000], | ||
timeouts: [500, 4000], | ||
batches: [20000, 60000], | ||
rss: [30000, 60000], | ||
completed: [100000, 200000], | ||
cacheHits: [25000, 70000], | ||
timeouts: [500, 8000], | ||
batches: [500, 4000], | ||
rss: [90000, 200000], | ||
avgBatchSize: [30, 50], | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/** | ||
* Test app worker - allows us to saturate the request generator without impacting the app | ||
*/ | ||
|
||
/* Requires ------------------------------------------------------------------*/ | ||
|
||
const settings = require('./settings'); | ||
const HA = require('../../src/index.js'); | ||
const {getAssets,getErroredRequest} = require('./dao'); | ||
const crypto = require('crypto'); | ||
|
||
/* Local variables -----------------------------------------------------------*/ | ||
|
||
let handbreak = false; | ||
|
||
const suite = { | ||
completed: 0, | ||
cacheHits: 0, | ||
sum: 0, | ||
timeouts: 0, | ||
batches: 0, | ||
avgBatchSize: 0, | ||
startHeap: process.memoryUsage().rss, | ||
}; | ||
|
||
const store = HA(settings.setup); | ||
|
||
/* Methods -------------------------------------------------------------------*/ | ||
|
||
function handleRequest(id, language) { | ||
const randomError = (Math.round(Math.random()*10) === 0); | ||
let finished = false; | ||
const before = Date.now(); | ||
setTimeout(() => { | ||
if (finished === false) suite.timeouts++; | ||
}, 500); | ||
if (randomError) store.config.resolver = getErroredRequest; | ||
else store.config.resolver = getAssets; | ||
store.get(id, { language }, crypto.randomBytes(8).toString('hex')) | ||
.then((result) => { | ||
finished = true; | ||
if (handbreak) return; | ||
if (!result || result.id !== id || result.language !== language) { | ||
console.log(result, 'does not match', id, language); | ||
throw new Error('integrity test failed'); | ||
} | ||
suite.sum += (Date.now() - before); | ||
suite.completed++; | ||
}, () => {}) | ||
.catch((err) => { console.log(err); process.exit(1)} ); | ||
} | ||
|
||
store.on('query', batch => { suite.batches++; suite.avgBatchSize += batch.ids.length; }); | ||
store.on('cacheHit', () => { suite.cacheHits++; }); | ||
|
||
//End | ||
async function complete() { | ||
handbreak = true; | ||
suite.avgBatchSize = Math.round(suite.avgBatchSize / suite.batches); | ||
suite.size = await store.size(); | ||
suite.startHeap = process.memoryUsage().rss - suite.startHeap; | ||
|
||
process.send(suite); | ||
} | ||
|
||
/* Init ----------------------------------------------------------------------*/ | ||
|
||
process.on('message', (msg) => msg === 'finish' ? complete() : handleRequest(msg.id, msg.language)); |