Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Changed tests to use helper.js

  • Loading branch information...
commit 5576a7cda4fcf3615d3368683e7fe75163da1fbb 1 parent 27a56c2
Pascal Opitz authored
42 tests/helper.js
View
@@ -0,0 +1,42 @@
+var bs = require('../lib/beanstalk_client');
+var net = require('net');
+
+var port = process.env.PORT || 11333;
+
+var mock = process.env.BEANSTALKD !== '1';
+var mock_server;
+
+var connection;
+
+module.exports = {
+ bind : function (fn, closeOnEnd) {
+
+ if(mock) {
+ mock_server = net.createServer(function(conn) {
+ connection = conn;
+
+ connection.on('data', function (data) {
+ fn.call(mock_server, connection, data);
+ });
+
+ if(closeOnEnd === true) {
+ closeOnEnd = function () {
+ mock_server.close();
+ }
+ }
+
+ if(closeOnEnd) {
+ connection.on('end', function () {
+ closeOnEnd.call(mock_server);
+ });
+ }
+ });
+
+ mock_server.listen(port);
+ }
+
+ },
+ getClient : function () {
+ return bs.Client('127.0.0.1:' + port);
+ }
+}
28 tests/test_ignore.js
View
@@ -1,25 +1,15 @@
-var assert = require('assert');
-var bs = require('../lib/beanstalk_client');
-
console.log('testing ignore');
-var port = 11333;
-
-var net = require('net');
-var mock_server = net.createServer(function(conn) {
- conn.on('data', function(data) {
- if(String(data) == "ignore default\r\n") {
- conn.write('WATCHING');
- }
- });
-
- conn.on('end', function() {
- mock_server.close();
- });
-});
-mock_server.listen(port);
+var assert = require('assert');
+var helper = require('./helper');
+
+helper.bind(function(conn, data) {
+ if(String(data) == "ignore default\r\n") {
+ conn.write('WATCHING');
+ }
+}, true);
+var client = helper.getClient();
-var client = bs.Client('127.0.0.1:' + port);
var success = false;
var error = false;
29 tests/test_kick.js
View
@@ -1,25 +1,14 @@
-var assert = require('assert');
-var bs = require('../lib/beanstalk_client');
-
console.log('testing kick');
-var port = 11333;
-
-var net = require('net');
-var mock_server = net.createServer(function(conn) {
- conn.on('data', function(data) {
- if(String(data) == "kick 10\r\n") {
- conn.write('KICKED');
- }
- });
-
- conn.on('end', function() {
- mock_server.close();
- });
-});
-mock_server.listen(port);
-
-var client = bs.Client('127.0.0.1:' + port);
+var assert = require('assert');
+var helper = require('./helper');
+
+helper.bind(function(conn, data) {
+ if(String(data) == "kick 10\r\n") {
+ conn.write('KICKED');
+ }
+}, true);
+var client = helper.getClient();
var success = false;
var error = false;
34 tests/test_list_tube_used.js
View
@@ -1,29 +1,19 @@
-var assert = require('assert');
-var bs = require('../lib/beanstalk_client');
-
console.log('testing list_tube_used');
-var port = 11333;
+var assert = require('assert');
+var helper = require('./helper');
-var net = require('net');
-var mock_server = net.createServer(function(conn) {
- conn.on('data', function(data) {
- if(String(data) == "list-tube-used\r\n") {
- var response = 'USING';
- response += "\r\n";
- response += "tube"
- response += "\r\n";
- conn.write(response);
- }
- });
-
- conn.on('end', function() {
- mock_server.close();
- });
-});
-mock_server.listen(port);
+helper.bind(function(conn, data) {
+ if(String(data) == "list-tube-used\r\n") {
+ var response = 'USING';
+ response += "\r\n";
+ response += "tube"
+ response += "\r\n";
+ conn.write(response);
+ }
+}, true);
+var client = helper.getClient();
-var client = bs.Client('127.0.0.1:' + port);
var success = false;
var error = false;
36 tests/test_list_tubes.js
View
@@ -1,29 +1,19 @@
-var assert = require('assert');
-var bs = require('../lib/beanstalk_client');
-
console.log('testing list_tubes');
-var port = 11333;
-
-var net = require('net');
-var mock_server = net.createServer(function(conn) {
- conn.on('data', function(data) {
- if(String(data) == "list-tubes\r\n") {
- var response = 'OK';
- response += "\r\n";
- response += "---\n- default\n - second\n"
- response += "\r\n";
- conn.write(response);
- }
- });
-
- conn.on('end', function() {
- mock_server.close();
- });
-});
-mock_server.listen(port);
+var assert = require('assert');
+var helper = require('./helper');
+
+helper.bind(function(conn, data) {
+ if(String(data) == "list-tubes\r\n") {
+ var response = 'OK';
+ response += "\r\n";
+ response += "---\n- default\n - second\n"
+ response += "\r\n";
+ conn.write(response);
+ }
+}, true);
+var client = helper.getClient();
-var client = bs.Client('127.0.0.1:' + port);
var success = false;
var error = false;
41 tests/test_list_tubes_watched.js
View
@@ -1,33 +1,24 @@
+console.log('testing list_tubes_watched');
+
var assert = require('assert');
-var bs = require('../lib/beanstalk_client');
+var helper = require('./helper');
-console.log('testing list_tubes_watched');
+helper.bind(function(conn, data) {
+ if(String(data) == "watch default\r\n") {
+ conn.write("WATCHING\r\n");
+ }
-var port = 11333;
-
-var net = require('net');
-var mock_server = net.createServer(function(conn) {
- conn.on('data', function(data) {
- if(String(data) == "watch default\r\n") {
- conn.write("WATCHING\r\n");
- }
-
- if(String(data) == "list-tubes-watched\r\n") {
- var response = 'OK';
- response += "\r\n";
- response += "---\n- default\n - second\n"
- response += "\r\n";
- conn.write(response);
- }
- });
+ if(String(data) == "list-tubes-watched\r\n") {
+ var response = 'OK';
+ response += "\r\n";
+ response += "---\n- default\n - second\n"
+ response += "\r\n";
+ conn.write(response);
+ }
+}, true);
+var client = helper.getClient();
- conn.on('end', function() {
- mock_server.close();
- });
-});
-mock_server.listen(port);
-var client = bs.Client('127.0.0.1:' + port);
var success = false;
var error = false;
38 tests/test_multiline_put.js
View
@@ -1,30 +1,24 @@
-var assert = require('assert');
-var bs = require('../lib/beanstalk_client');
-
console.log('testing multiline put, peek, delete');
-var port = 11333;
-
-var net = require('net');
-var mock_server = net.createServer(function(conn) {
- conn.on('data', function(data) {
- if(String(data).indexOf('put') > -1) {
- conn.write("INSERTED 10\r\n");
- }
-
- if(String(data) == 'peek 10\r\n') {
- conn.write("FOUND 10 13\r\ntest\r\nhere\r\n\r\n");
- }
+var assert = require('assert');
+var helper = require('./helper');
- if(String(data) == "delete 10\r\n") {
- conn.write("DELETED\r\n");
- mock_server.close();
- }
- });
+helper.bind(function(conn, data) {
+ if(String(data).indexOf('put') > -1) {
+ conn.write("INSERTED 10\r\n");
+ }
+
+ if(String(data) == 'peek 10\r\n') {
+ conn.write("FOUND 10 13\r\ntest\r\nhere\r\n\r\n");
+ }
+
+ if(String(data) == "delete 10\r\n") {
+ conn.write("DELETED\r\n");
+ this.close();
+ }
});
-mock_server.listen(port);
+var client = helper.getClient();
-var client = bs.Client('127.0.0.1:' + port);
var success = false;
var error = false;
66 tests/test_peek_buried.js
View
@@ -1,49 +1,39 @@
-var assert = require('assert');
-var bs = require('../lib/beanstalk_client');
-
console.log('testing use, put, watch, reserve, bury, peek_buried');
-var port = 11333;
+var assert = require('assert');
+var helper = require('./helper');
-var net = require('net');
-var mock_server = net.createServer(function(conn) {
- conn.on('data', function(data) {
- if(String(data) == 'use burytest\r\n') {
- conn.write("USING\r\n");
- }
+helper.bind(function(conn, data) {
+ if(String(data) == 'use burytest\r\n') {
+ conn.write("USING\r\n");
+ }
- if(String(data).indexOf('put') > -1) {
- conn.write("INSERTED 9\r\n");
- }
-
- if(String(data) == 'watch burytest\r\n') {
- conn.write("WATCHING\r\n");
- }
-
- if(String(data) == 'reserve\r\n') {
- conn.write("RESERVED 9 8\r\nburytest\r\n");
- }
+ if(String(data).indexOf('put') > -1) {
+ conn.write("INSERTED 9\r\n");
+ }
+
+ if(String(data) == 'watch burytest\r\n') {
+ conn.write("WATCHING\r\n");
+ }
+
+ if(String(data) == 'reserve\r\n') {
+ conn.write("RESERVED 9 8\r\nburytest\r\n");
+ }
- if(String(data) == 'bury 9 10\r\n') {
- conn.write("BURIED\r\n");
- }
+ if(String(data) == 'bury 9 10\r\n') {
+ conn.write("BURIED\r\n");
+ }
- if(String(data) == 'peek-buried\r\n') {
- conn.write("FOUND 9 8\r\nburytest\r\n");
- }
+ if(String(data) == 'peek-buried\r\n') {
+ conn.write("FOUND 9 8\r\nburytest\r\n");
+ }
- if(String(data) == "delete 9\r\n") {
- conn.write("DELETED\r\n");
- }
- });
-
- conn.on('end', function() {
- mock_server.close();
- });
-});
-mock_server.listen(port);
+ if(String(data) == "delete 9\r\n") {
+ conn.write("DELETED\r\n");
+ }
+}, true);
+var client = helper.getClient();
-var client = bs.Client('127.0.0.1:' + port);
var success = false;
var error = false;
26 tests/test_peek_delayed.js
View
@@ -1,25 +1,15 @@
-var assert = require('assert');
-var bs = require('../lib/beanstalk_client');
-
console.log('testing peek_delayed');
-var port = 11333;
+var assert = require('assert');
+var helper = require('./helper');
-var net = require('net');
-var mock_server = net.createServer(function(conn) {
- conn.on('data', function(data) {
- if(String(data) == 'peek-delayed\r\n') {
- conn.write("OK\r\n");
- }
- });
-
- conn.on('end', function(){
- mock_server.close();
- })
-});
-mock_server.listen(port);
+helper.bind(function(conn, data) {
+ if(String(data) == 'peek-delayed\r\n') {
+ conn.write("OK\r\n");
+ }
+}, true);
+var client = helper.getClient();
-var client = bs.Client('127.0.0.1:' + port);
var success = false;
var error = false;
38 tests/test_peek_ready.js
View
@@ -1,33 +1,23 @@
-var assert = require('assert');
-var bs = require('../lib/beanstalk_client');
-
console.log('testing put, peek_ready, delete');
-var port = 11333;
+var assert = require('assert');
+var helper = require('./helper');
-var net = require('net');
-var mock_server = net.createServer(function(conn) {
- conn.on('data', function(data) {
- if(String(data).indexOf('put') > -1) {
- conn.write("INSERTED 10\r\n");
- }
+helper.bind(function(conn, data) {
+ if(String(data).indexOf('put') > -1) {
+ conn.write("INSERTED 10\r\n");
+ }
- if(String(data) == 'peek-ready\r\n') {
- conn.write("FOUND 10 7\r\ntest\r\n");
- }
+ if(String(data) == 'peek-ready\r\n') {
+ conn.write("FOUND 10 7\r\ntest\r\n");
+ }
- if(String(data) == 'delete 10\r\n') {
- conn.write("DELETED\r\n");
- }
- });
-
- conn.on('end', function(){
- mock_server.close();
- })
-});
-mock_server.listen(port);
+ if(String(data) == 'delete 10\r\n') {
+ conn.write("DELETED\r\n");
+ }
+}, true);
+var client = helper.getClient();
-var client = bs.Client('127.0.0.1:' + port);
var success = false;
var error = false;
35 tests/test_put_in_forloop.js
View
@@ -1,29 +1,22 @@
-var assert = require('assert');
-var bs = require('../lib/beanstalk_client');
-
console.log('testing put in forloop');
-var port = 11333;
+var assert = require('assert');
+var helper = require('./helper');
-var net = require('net');
var cnt = 0;
-var mock_server = net.createServer(function(conn) {
- conn.on('data', function(data) {
- if(String(data).indexOf('put') > -1) {
- cnt += 1;
- conn.write("INSERTED "+cnt+"\r\n");
- }
-
- if(String(data) == "use default\r\n") {
- conn.write('USING default\r\n');
- mock_server.close();
- }
- });
-});
-mock_server.listen(port);
-
-var client = bs.Client('127.0.0.1:' + port);
+helper.bind(function(conn, data) {
+ if(String(data).indexOf('put') > -1) {
+ cnt += 1;
+ conn.write("INSERTED "+cnt+"\r\n");
+ }
+
+ if(String(data) == "use default\r\n") {
+ conn.write('USING default\r\n');
+ this.close();
+ }
+}, false);
+var client = helper.getClient();
client.use('default').onSuccess(function(data) {
var completed = 0;
38 tests/test_put_peek_delete.js
View
@@ -1,33 +1,23 @@
-var assert = require('assert');
-var bs = require('../lib/beanstalk_client');
-
console.log('testing put, peek, delete');
-var port = 11333;
+var assert = require('assert');
+var helper = require('./helper');
-var net = require('net');
-var mock_server = net.createServer(function(conn) {
- conn.on('data', function(data) {
- if(String(data).indexOf('put') > -1) {
- conn.write("INSERTED 10\r\n");
- }
+helper.bind(function(conn, data) {
+ if(String(data).indexOf('put') > -1) {
+ conn.write("INSERTED 10\r\n");
+ }
- if(String(data) == 'peek 10\r\n') {
- conn.write("FOUND 10 7\r\ntest\r\n");
- }
+ if(String(data) == 'peek 10\r\n') {
+ conn.write("FOUND 10 7\r\ntest\r\n");
+ }
- if(String(data) == 'delete 10\r\n') {
- conn.write("DELETED\r\n");
- }
- });
-
- conn.on('end', function(){
- mock_server.close();
- })
-});
-mock_server.listen(port);
+ if(String(data) == 'delete 10\r\n') {
+ conn.write("DELETED\r\n");
+ }
+}, true);
+var client = helper.getClient();
-var client = bs.Client('127.0.0.1:' + port);
var success = false;
var error = false;
72 tests/test_put_stats_job_delete.js
View
@@ -1,50 +1,40 @@
-var assert = require('assert');
-var bs = require('../lib/beanstalk_client');
-
console.log('testing put stats_job');
-var port = 11333;
+var assert = require('assert');
+var helper = require('./helper');
-var net = require('net');
-var mock_server = net.createServer(function(conn) {
- conn.on('data', function(data) {
- if(String(data).indexOf('put') > -1) {
- conn.write("INSERTED 3\r\n");
- }
+helper.bind(function(conn, data) {
+ if(String(data).indexOf('put') > -1) {
+ conn.write("INSERTED 3\r\n");
+ }
- if(String(data) == 'stats-job 3\r\n') {
- response = "";
- response += "OK 141\r\n";
- response += "---\n";
- response += "id: 3\n";
- response += "tube: default\n";
- response += "state: ready\n";
- response += "pri: 10\n";
- response += "age: 0\n";
- response += "delay: 0\n";
- response += "ttr: 100000\n";
- response += "time-left: 0\n";
- response += "reserves: 0\n";
- response += "timeouts: 0\n";
- response += "releases: 0\n";
- response += "buries: 0\n";
- response += "kicks: 0\n";
- response += "\r\n";
- conn.write(response);
- }
+ if(String(data) == 'stats-job 3\r\n') {
+ response = "";
+ response += "OK 141\r\n";
+ response += "---\n";
+ response += "id: 3\n";
+ response += "tube: default\n";
+ response += "state: ready\n";
+ response += "pri: 10\n";
+ response += "age: 0\n";
+ response += "delay: 0\n";
+ response += "ttr: 100000\n";
+ response += "time-left: 0\n";
+ response += "reserves: 0\n";
+ response += "timeouts: 0\n";
+ response += "releases: 0\n";
+ response += "buries: 0\n";
+ response += "kicks: 0\n";
+ response += "\r\n";
+ conn.write(response);
+ }
- if(String(data) == 'delete 3\r\n') {
- conn.write("DELETED\r\n");
- }
- });
-
- conn.on('end', function(){
- mock_server.close();
- })
-});
-mock_server.listen(port);
+ if(String(data) == 'delete 3\r\n') {
+ conn.write("DELETED\r\n");
+ }
+}, true);
+var client = helper.getClient();
-var client = bs.Client('127.0.0.1:' + port);
var success = false;
var error = false;
30 tests/test_quit.js
View
@@ -1,26 +1,20 @@
-var assert = require('assert');
-var bs = require('../lib/beanstalk_client');
-
console.log('testing quit');
-var port = 11333;
+var assert = require('assert');
+var helper = require('./helper');
-var net = require('net');
-var mock_server = net.createServer(function(conn) {
- conn.on('data', function(data) {
- if(String(data) == "use default\r\n") {
- conn.write('USING default\r\n');
- }
+helper.bind(function(conn, data) {
+ if(String(data) == "use default\r\n") {
+ conn.write('USING default\r\n');
+ }
- if(String(data) == "quit\r\n") {
- conn.destroy();
- mock_server.close();
- }
- });
-});
-mock_server.listen(port);
+ if(String(data) == "quit\r\n") {
+ conn.destroy();
+ this.close();
+ }
+}, false);
+var client = helper.getClient();
-var client = bs.Client('127.0.0.1:' + port);
var success = false;
var closed = false;
63 tests/test_reserve.js
View
@@ -1,49 +1,42 @@
-var assert = require('assert');
-var bs = require('../lib/beanstalk_client');
-
console.log('testing watch, reserve, use, put');
var port = 11333;
-var net = require('net');
var disconnected = 0;
-var mock_server = net.createServer(function(conn) {
-
- conn.on('data', function(data) {
- if(String(data) == 'use reservetest\r\n') {
- conn.write("USING\r\n");
- }
+var assert = require('assert');
+var helper = require('./helper');
- if(String(data).indexOf('put') > -1) {
- conn.write("INSERTED 9\r\n");
- }
-
- if(String(data) == 'watch reservetest\r\n') {
- conn.write("WATCHING\r\n");
- }
-
- if(String(data) == 'reserve\r\n') {
- conn.write("RESERVED 9 4\r\ntest\r\n");
- }
+helper.bind(function(conn, data) {
+ if(String(data) == 'use reservetest\r\n') {
+ conn.write("USING\r\n");
+ }
- if(String(data) == "delete 9\r\n") {
- conn.write("DELETED\r\n");
- }
- });
+ if(String(data).indexOf('put') > -1) {
+ conn.write("INSERTED 9\r\n");
+ }
- conn.on('end', function() {
- disconnected = disconnected + 1;
-
- if(disconnected == 2) {
- mock_server.close();
- }
- });
+ if(String(data) == 'watch reservetest\r\n') {
+ conn.write("WATCHING\r\n");
+ }
+
+ if(String(data) == 'reserve\r\n') {
+ conn.write("RESERVED 9 4\r\ntest\r\n");
+ }
+
+ if(String(data) == "delete 9\r\n") {
+ conn.write("DELETED\r\n");
+ }
+}, function() {
+ disconnected = disconnected + 1;
+
+ if(disconnected == 2) {
+ this.close();
+ }
});
-mock_server.listen(port);
-var client = bs.Client('127.0.0.1:' + port);
-var client2 = bs.Client('127.0.0.1:' + port);
+var client = helper.getClient();
+var client2 = helper.getClient();
var success = false;
var error = false;
28 tests/test_reserve_with_timeout.js
View
@@ -1,27 +1,15 @@
-var assert = require('assert');
-var bs = require('../lib/beanstalk_client');
-
console.log('testing reserve_with_timeout');
-var port = 11333;
-
-var net = require('net');
+var assert = require('assert');
+var helper = require('./helper');
-var mock_server = net.createServer(function(conn) {
-
- conn.on('data', function(data) {
- if(String(data) == 'reserve-with-timeout 2\r\n') {
- conn.write("RESERVED 9 4\r\ntest\r\n");
- }
- });
-
- conn.on('end', function() {
- mock_server.close();
- });
-});
-mock_server.listen(port);
+helper.bind(function(conn, data) {
+ if(String(data) == 'reserve-with-timeout 2\r\n') {
+ conn.write("RESERVED 9 4\r\ntest\r\n");
+ }
+}, true);
+var client = helper.getClient();
-var client = bs.Client('127.0.0.1:' + port);
var success = false;
var error = false;
122 tests/test_stats.js
View
@@ -1,73 +1,63 @@
-var assert = require('assert');
-var bs = require('../lib/beanstalk_client');
-
console.log('testing stats');
-var port = 11333;
+var assert = require('assert');
+var helper = require('./helper');
-var net = require('net');
-var mock_server = net.createServer(function(conn) {
- conn.on('data', function(data) {
- if(String(data) == 'stats\r\n') {
- var response = "";
- response += "OK 813\r\n";
- response += "---\n";
- response += "current-jobs-urgent: 0\n";
- response += "current-jobs-ready: 0\n";
- response += "current-jobs-reserved: 0\n";
- response += "current-jobs-delayed: 0\n";
- response += "current-jobs-buried: 0\n";
- response += "cmd-put: 10\n";
- response += "cmd-peek: 2\n";
- response += "cmd-peek-ready: 0\n";
- response += "cmd-peek-delayed: 0\n";
- response += "cmd-peek-buried: 1\n";
- response += "cmd-reserve: 2\n";
- response += "cmd-reserve-with-timeout: 0\n";
- response += "cmd-delete: 10\n";
- response += "cmd-release: 0\n";
- response += "cmd-use: 2\n";
- response += "cmd-watch: 2\n";
- response += "cmd-ignore: 0\n";
- response += "cmd-bury: 1\n";
- response += "cmd-kick: 0\n";
- response += "cmd-touch: 0\n";
- response += "cmd-stats: 1\n";
- response += "cmd-stats-job: 6\n";
- response += "cmd-stats-tube: 0\n";
- response += "cmd-list-tubes: 15\n";
- response += "cmd-list-tube-used: 0\n";
- response += "cmd-list-tubes-watched: 0\n";
- response += "cmd-pause-tube: 0\n";
- response += "job-timeouts: 0\n";
- response += "total-jobs: 10\n";
- response += "max-job-size: 65535\n";
- response += "current-tubes: 1\n";
- response += "current-connections: 1\n";
- response += "current-producers: 0\n";
- response += "current-workers: 0\n";
- response += "current-waiting: 0\n";
- response += "total-connections: 27\n";
- response += "pid: 2759\n";
- response += "version: 1.4.6\n";
- response += "rusage-utime: 0.000000\n";
- response += "rusage-stime: 0.028001\n";
- response += "uptime: 19109\n";
- response += "binlog-oldest-index: 0\n";
- response += "binlog-current-index: 0\n";
- response += "binlog-max-size: 10485760\n";
- response += "\r\n";
- conn.write(response);
- }
- });
-
- conn.on('end', function(){
- mock_server.close();
- })
-});
-mock_server.listen(port);
+helper.bind(function(conn, data) {
+ if(String(data) == 'stats\r\n') {
+ var response = "";
+ response += "OK 813\r\n";
+ response += "---\n";
+ response += "current-jobs-urgent: 0\n";
+ response += "current-jobs-ready: 0\n";
+ response += "current-jobs-reserved: 0\n";
+ response += "current-jobs-delayed: 0\n";
+ response += "current-jobs-buried: 0\n";
+ response += "cmd-put: 10\n";
+ response += "cmd-peek: 2\n";
+ response += "cmd-peek-ready: 0\n";
+ response += "cmd-peek-delayed: 0\n";
+ response += "cmd-peek-buried: 1\n";
+ response += "cmd-reserve: 2\n";
+ response += "cmd-reserve-with-timeout: 0\n";
+ response += "cmd-delete: 10\n";
+ response += "cmd-release: 0\n";
+ response += "cmd-use: 2\n";
+ response += "cmd-watch: 2\n";
+ response += "cmd-ignore: 0\n";
+ response += "cmd-bury: 1\n";
+ response += "cmd-kick: 0\n";
+ response += "cmd-touch: 0\n";
+ response += "cmd-stats: 1\n";
+ response += "cmd-stats-job: 6\n";
+ response += "cmd-stats-tube: 0\n";
+ response += "cmd-list-tubes: 15\n";
+ response += "cmd-list-tube-used: 0\n";
+ response += "cmd-list-tubes-watched: 0\n";
+ response += "cmd-pause-tube: 0\n";
+ response += "job-timeouts: 0\n";
+ response += "total-jobs: 10\n";
+ response += "max-job-size: 65535\n";
+ response += "current-tubes: 1\n";
+ response += "current-connections: 1\n";
+ response += "current-producers: 0\n";
+ response += "current-workers: 0\n";
+ response += "current-waiting: 0\n";
+ response += "total-connections: 27\n";
+ response += "pid: 2759\n";
+ response += "version: 1.4.6\n";
+ response += "rusage-utime: 0.000000\n";
+ response += "rusage-stime: 0.028001\n";
+ response += "uptime: 19109\n";
+ response += "binlog-oldest-index: 0\n";
+ response += "binlog-current-index: 0\n";
+ response += "binlog-max-size: 10485760\n";
+ response += "\r\n";
+ conn.write(response);
+ }
+}, true);
+var client = helper.getClient();
-var client = bs.Client('127.0.0.1:' + port);
var success = false;
var error = false;
26 tests/test_stats_job.js
View
@@ -1,25 +1,15 @@
-var assert = require('assert');
-var bs = require('../lib/beanstalk_client');
-
console.log('testing stats_job not existing');
-var port = 11333;
-
-var net = require('net');
-var mock_server = net.createServer(function(conn) {
- conn.on('data', function(data) {
- if(String(data) == "stats-job 111111111\r\n") {
- conn.write('NOT_FOUND\r\n');
- }
- });
+var assert = require('assert');
+var helper = require('./helper');
- conn.on('end', function() {
- mock_server.close();
- });
-});
-mock_server.listen(port);
+helper.bind(function(conn, data) {
+ if(String(data) == "stats-job 111111111\r\n") {
+ conn.write('NOT_FOUND\r\n');
+ }
+}, true);
+var client = helper.getClient();
-var client = bs.Client('127.0.0.1:' + port);
var success = false;
var error = false;
62 tests/test_stats_tube.js
View
@@ -1,42 +1,32 @@
-var assert = require('assert');
-var bs = require('../lib/beanstalk_client');
-
console.log('testing stats_tube');
-var port = 11333;
-
-var net = require('net');
-var mock_server = net.createServer(function(conn) {
- conn.on('data', function(data) {
- if(String(data) == 'stats-tube default\r\n') {
- var response = "";
- response += "OK 251\r\n";
- response += "---\n";
- response += "name: default\n";
- response += "current-jobs-urgent: 0\n";
- response += "current-jobs-ready: 0\n";
- response += "current-jobs-reserved: 0\n";
- response += "current-jobs-delayed: 0\n";
- response += "current-jobs-buried: 0\n";
- response += "total-jobs: 8\n";
- response += "current-using: 1\n";
- response += "current-watching: 1\n";
- response += "current-waiting: 0\n";
- response += "cmd-pause-tube: 0\n";
- response += "pause: 0\n";
- response += "pause-time-left: 0\n";
- response += "\r\n";
- conn.write(response);
- }
- });
-
- conn.on('end', function(){
- mock_server.close();
- })
-});
-mock_server.listen(port);
+var assert = require('assert');
+var helper = require('./helper');
+
+helper.bind(function(conn, data) {
+ if(String(data) == 'stats-tube default\r\n') {
+ var response = "";
+ response += "OK 251\r\n";
+ response += "---\n";
+ response += "name: default\n";
+ response += "current-jobs-urgent: 0\n";
+ response += "current-jobs-ready: 0\n";
+ response += "current-jobs-reserved: 0\n";
+ response += "current-jobs-delayed: 0\n";
+ response += "current-jobs-buried: 0\n";
+ response += "total-jobs: 8\n";
+ response += "current-using: 1\n";
+ response += "current-watching: 1\n";
+ response += "current-waiting: 0\n";
+ response += "cmd-pause-tube: 0\n";
+ response += "pause: 0\n";
+ response += "pause-time-left: 0\n";
+ response += "\r\n";
+ conn.write(response);
+ }
+}, true);
+var client = helper.getClient();
-var client = bs.Client('127.0.0.1:' + port);
var success = false;
var error = false;
25 tests/test_use.js
View
@@ -1,22 +1,17 @@
-var assert = require('assert');
-var bs = require('../lib/beanstalk_client');
-
console.log('testing use');
-var port = 11333;
+var assert = require('assert');
+var helper = require('./helper');
+
+helper.bind(function(conn, data) {
+ if(String(data) == "use default\r\n") {
+ conn.write('USING default\r\n');
+ this.close();
+ }
+}, false);
+var client = helper.getClient();
-var net = require('net');
-var mock_server = net.createServer(function(conn) {
- conn.on('data', function(data) {
- if(String(data) == "use default\r\n") {
- conn.write('USING default\r\n');
- mock_server.close();
- }
- });
-});
-mock_server.listen(port);
-var client = bs.Client('127.0.0.1:' + port);
var success = false;
var error = false;
57 tests/test_utf8.js
View
@@ -1,41 +1,32 @@
-var assert = require('assert');
-var bs = require('../lib/beanstalk_client');
-
console.log('testing utf8');
-var port = 11333;
-
-var net = require('net');
var cnt = 0;
-var mock_server = net.createServer(function(conn) {
- conn.on('data', function(data) {
-
-
- if(String(data).indexOf('put') > -1) {
- var input = data.toString().split('\r\n');
-
- assert.equal(input[1], "ééééé");
- assert.equal(Buffer.byteLength(input[1], 'utf8'), Buffer.byteLength("ééééé", 'utf8'));
-
- cnt += 1;
- conn.write("INSERTED "+cnt+"\r\n");
- }
-
- if(String(data) == "use default\r\n") {
- conn.write('USING default\r\n');
- mock_server.close();
- }
- });
-});
-mock_server.listen(port);
-
-var client = bs.Client('127.0.0.1:' + port);
+var assert = require('assert');
+var helper = require('./helper');
+
+helper.bind(function(conn, data) {
+ if(String(data).indexOf('put') > -1) {
+ var input = data.toString().split('\r\n');
+
+ assert.equal(input[1], "ééééé");
+ assert.equal(Buffer.byteLength(input[1], 'utf8'), Buffer.byteLength("ééééé", 'utf8'));
+
+ cnt += 1;
+ conn.write("INSERTED "+cnt+"\r\n");
+ }
+
+ if(String(data) == "use default\r\n") {
+ conn.write('USING default\r\n');
+ this.close();
+ }
+}, false);
+var client = helper.getClient();
client.use('default').onSuccess(function(data) {
- client.put("ééééé", 100, 0).onSuccess(function(data) {
- assert.ok(!isNaN(data[0]));
- client.disconnect();
- });
+ client.put("ééééé", 100, 0).onSuccess(function(data) {
+ assert.ok(!isNaN(data[0]));
+ client.disconnect();
+ });
});
23 tests/test_watch.js
View
@@ -1,22 +1,15 @@
-var assert = require('assert');
-var bs = require('../lib/beanstalk_client');
-
console.log('testing watch');
-var port = 11333;
+var assert = require('assert');
+var helper = require('./helper');
-var net = require('net');
-var mock_server = net.createServer(function(conn) {
- conn.on('data', function(data) {
- if(String(data) == "watch default\r\n") {
- conn.write('WATCHING 1\r\n');
- mock_server.close();
- }
- });
+helper.bind(function(conn, data) {
+ if(String(data) == "watch default\r\n") {
+ conn.write('WATCHING 1\r\n');
+ this.close();
+ }
});
-mock_server.listen(port);
-
-var client = bs.Client('127.0.0.1:' + port);
+var client = helper.getClient();
var success = false;
var error = false;
Please sign in to comment.
Something went wrong with that request. Please try again.