Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('caches concurrent requests to the appropriate file', function(done) {
// Fire off 20 concurrent requests and ensure that all the cached responses
// end up in the appropriate place.
async.times(20, function(index, next) {
var randomInput = Math.random().toString();
var url = '/echo_chunked?input=' + randomInput;
var cacheKey = ['GET', 'localhost:9333', url].join('');
var cacheBase = crypto.createHash('sha256').update(cacheKey).digest('hex');
request.get('http://localhost:9333' + url, function(error, response, body) {
next(null, {
url: url,
input: randomInput,
output: body,
cacheBase: cacheBase,
});
});
}, function(error, requests) {
setTimeout(function() {
it('returns 429 over rate limit error when the requests per second exceeds the rate limit plus burst', function(done) {
this.timeout(7000);
async.times(40, function(index, callback) {
request.get('http://localhost:9080/info/', this.options, function(error, response) {
callback(error, response.statusCode);
});
}.bind(this), function(error, responseCodes) {
should.not.exist(error);
var successes = _.filter(responseCodes, function(code) { return code === 200; });
var overLimits = _.filter(responseCodes, function(code) { return code === 429; });
responseCodes.length.should.eql(40);
// The rate limiting and burst handling is a bit fuzzy since we
// don't know exactly when the initial rate limit has been exceeded
// (since nginx limits aren't based on hard counts, but instead the
// average rate of requests, and we also don't know how fast the
// nodejs tests are actually making requests). Since we don't know
// when the burst kicks in, just make sure we generally start
function findUnusedFile(nonce, next) {
var filepath = internalGetStreamFilepath(false, nonce);
var filepathgz = internalGetStreamFilepath(true, nonce);
async.each([
filepath,
filepathgz
], function (potentialpath, pathresult) {
fs.stat(potentialpath, function (err, stats) {
if (err && err.code === 'ENOENT') {
// File doesn't already exist, this is good
pathresult();
} else if (err) {
// Something else failed
pathresult(err);
} else {
// Path existed, use something else
pathresult('inuse');
}
})
}, function (err) {
helpers.createAddresses = function(server, wallet, main, change, cb) {
// var clock = sinon.useFakeTimers('Date');
async.mapSeries(_.range(main + change), function(i, next) {
// clock.tick(1000);
var address = wallet.createAddress(i >= main);
server.storage.storeAddressAndWallet(wallet, address, function(err) {
next(err, address);
});
}, function(err, addresses) {
should.not.exist(err);
// clock.restore();
return cb(_.take(addresses, main), _.takeRight(addresses, change));
});
};
setTimeout(function() {
// Perform a number of requests to make sure any local worker
// cache is cleared across all possible worker processes.
async.times(20, function(index, timesCallback) {
request.get(url, function(error, response) {
response.headers['x-ratelimit-limit'].should.eql('90');
timesCallback();
}.bind(this));
}.bind(this), done);
}.bind(this), 2100);
}.bind(this));
txs.sort(function(a, b) {
var b = (b.firstSeenTs || b.ts)+ b.txid;
var a = (a.firstSeenTs || a.ts)+ a.txid;
if (a > b) return -1;
if (a < b) return 1;
return 0;
});
txs = txs.slice(from, to);
var txIndex = {};
_.each(txs, function(tx) {
txIndex[tx.txid] = tx;
});
async.eachLimit(txs, RPC_CONCURRENCY, function(tx2, callback) {
tDb.fromIdWithInfo(tx2.txid, function(err, tx) {
if (err) {
console.log(err);
return common.handleErrors(err, res);
}
if (tx && tx.info) {
if (tx2.firstSeenTs)
tx.info.firstSeenTs = tx2.firstSeenTs;
txIndex[tx.txid].info = tx.info;
} else {
// TX no longer available
txIndex[tx2.txid].info = {
txid: tx2.txid,
possibleDoubleSpend: true,
function executeTests(manifest, callback) {
async.mapLimit(manifest.tests, workers,
// 1.2.1 Execute an individual test
function (test, callback) {
async.series({
actionStream: self._fetch.bind(self, test.action),
resultStream: self._fetch.bind(self, test.result),
},
function (error, results) {
if (error) return callback(error);
self._performTest(test, results.actionStream, callback);
});
},
// 1.2.2 Show the summary of all performed tests
function showSummary(error, tests) {
var score = tests.reduce(function (sum, test) { return sum + test.success; }, 0);
manifest.skipped.forEach(function (test) { self._verifyResult(test); });
console.log(('* passed ' + score +
"getBuildLogs": (mCb) => {
// jobLogs: '/api/repos/#OWNER#/#REPO#/logs/#BUILD_NUMBER#/#JOB_ID#'
async.eachSeries(jobIds, (oneJobId, fCb) => {
params = {
uri: utils.getDomain(opts.settings.domain + config.api.url.jobLogs).replace('#JOB_ID#', oneJobId).replace("#BUILD_NUMBER#", oneBranch.number).replace("#OWNER#", opts.settings.owner).replace("#REPO#", opts.params.repo.split("/")[1]),
headers: config.headers,
json: true
};
params.headers['Authorization'] = opts.settings.ciToken;
if (opts.settings.domain) {
params.headers['Host'] = opts.settings.domain.replace(/https?:\/\//, "");
}
opts.log.debug(params);
request.get(params, (error, resp, body) => {
if (body && body.error) {
opts.log.error(body);
}
utils.checkError(error, { code: 997 }, cb, () => {
if (body && Array.isArray(body) && body.length > 0){
function main ( host) {
async.waterfall([
function (cb) {
getSpeechService(host, cb);
//console.log("start");
},
// [START send_request]
function sendRequest (speechService, cb) {
console.log(chalk.green('GOOGLE SPEACH DEAMON : Analyzing speech...'));
var startOfSpeech = false;
var responses = [];
var responseTimeout = null;
var call = speechService.streamingRecognize();
// Listen for various responses
bucket: bucket,
keys: _get_keys(batch),
jobBucket: bucket,
jobId: jobId,
nReducers: nReducers,
stepId: stepId,
reducerId: i
})
};
lambdaBatchParams.push(params);
}
console.log("LBR", lambdaBatchParams);
/// Stream the files from S3 & Reduce
async.map(lambdaBatchParams, invokeLambda, function (err, rResults){
if (err){
console.error(err);
callback(null, 'Reducer invocation error');
return;
}
var fname = jobId + "/reducerstate." + stepId;
writeReducerState(nReducers, nS3, bucket, fname, function(err, data){
callback(null, 'Invoked Reducer Step');
});
});
});
}else{