Skip to content

Instantly share code, notes, and snippets.

@benjamind
Last active December 15, 2015 10:48
Show Gist options
  • Save benjamind/5247953 to your computer and use it in GitHub Desktop.
Save benjamind/5247953 to your computer and use it in GitHub Desktop.
Test case for bug involving large strings in couchnode
var couchbase = require('couchbase'),
async = require('async'),
couchbaseConfig = {
debug: process.env.COUCHBASE_DEBUG || false,
user: process.env.COUCHBASE_USER || '',
password: process.env.COUCHBASE_PASSWORD || '',
bucket: process.env.COUCHBASE_BUCKET || 'default'
},
bucket = null;
if (process.env.COUCHBASE_HOSTS) {
couchbaseConfig.hosts = process.env.COUCHBASE_HOSTS.split(',');
} else {
if (process.env.COUCHBASE_HOST) {
couchbaseConfig.hosts = [ process.env.COUCHBASE_HOST ];
} else {
console.log('Warning: no COUCHBASE_HOSTS specified - Using localhost:8091');
couchbaseConfig.hosts = [ 'localhost:8091' ];
}
}
var count = 0;
function done(err) {
if (err) {
console.log('ERR : ' + err);
}
console.log('Executed ' + count + ' times');
setTimeout(function() {
process.exit(1);
},500);
}
couchbase.connect(couchbaseConfig, function (err, bkt) {
// create documents
var longString = "";
for (var i=0; i < 5000; i++) {
longString += 'a';
}
var tests = [];
for (var i=1; i < 5; i++) {
tests.push('test::' + i);
}
// store object
async.eachSeries(tests, function(item, callback) {
console.log('Creating item ' + item);
bkt.set(item, {
id: item,
otherItem: 'test',
longString: longString
}, function(err, meta) {
if (err) {
console.log('Error creating test data ' + item + ' : ' + err);
return callback(err);
}
console.log('Item created');
callback();
});
},function(err) {
if (err) {
console.log('Error creating items : ' + err);
setTimeout(function() {
process.exit(1);
},500);
} else {
console.log('Beginning test');
setTimeout(function() {
async.whilst(
function() {
return count < 50;
},
function(callback) {
bkt.get(tests, function(err, item) {
console.log('Single item err : ' + err);
console.log('Single item callback');
}, function(err, items) {
console.log('All items err : ' + err);
console.log('All items callback - ' + items.length);
count++;
callback();
});
},
function(err) {
// failed!
done(err,[]);
}
);
},500);
}
});
});
{
"name": "largestringtest",
"description": "large string test for couchnode",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node app"
},
"engines": {
"node": "0.8.18",
"npm": "1.1.x"
},
"dependencies": {
"couchbase": "*",
"async": "*"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment