From 2a5df5d7c547f62ca02b072f375f9ac5ab12c83b Mon Sep 17 00:00:00 2001 From: Brian Carlson Date: Wed, 23 Feb 2011 23:11:13 -0600 Subject: [PATCH] added stress tests for native bindings --- test/native/stress-tests.js | 49 +++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 test/native/stress-tests.js diff --git a/test/native/stress-tests.js b/test/native/stress-tests.js new file mode 100644 index 0000000..9dce3fe --- /dev/null +++ b/test/native/stress-tests.js @@ -0,0 +1,49 @@ +var helper = require(__dirname + "/../test-helper"); +var Client = require(__dirname + "/../../lib/native").Client; + +test('many rows', function() { + var client = new Client(helper.connectionString()); + client.connect(); + var q = client.query("SELECT * FROM person"); + var rows = []; + q.on('row', function(row) { + rows.push(row) + }); + assert.emits(q, 'end', function() { + client.end(); + assert.length(rows, 26); + }) +}); + +test('many queries', function() { + var client = new Client(helper.connectionString()); + client.connect(); + var count = 0; + var expected = 100; + for(var i = 0; i < expected; i++) { + var q = client.query("SELECT * FROM person"); + assert.emits(q, 'end', function() { + count++; + }) + } + assert.emits(client, 'drain', function() { + client.end(); + assert.equal(count, expected); + }) +}) + +test('many clients', function() { + var clients = []; + for(var i = 0; i < 20; i++) { + clients.push(new Client(helper.connectionString())); + } + clients.forEach(function(client) { + client.connect(); + for(var i = 0; i < 20; i++) { + client.query('SELECT * FROM person'); + } + assert.emits(client, 'drain', function() { + client.end(); + }) + }) +})