Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

added tests (nodeunit)

  • Loading branch information...
commit 29479d92570ee58942566d9a2645d87babf3f5e7 1 parent bdb9eab
andris9 authored

Showing 4 changed files with 547 additions and 74 deletions. Show diff stats Hide diff stats

  1. +30 3 README.md
  2. +7 12 gearman-connection.js
  3. +69 59 gearnode.js
  4. +441 0 tests.js
33 README.md
Source Rendered
@@ -4,6 +4,17 @@
4 4
5 5 **NB!** this is usable beta but probably not yet ready for production, I'll yet have to do a lot of refactoring and optimization
6 6
  7 +## Installation
  8 +
  9 + npm install gearnode
  10 +
  11 +## Tests
  12 +
  13 +Tests are run with *nodeunit*
  14 +
  15 + npm install nodeunit -g
  16 + nodeunit test.js
  17 +
7 18 ## Usage
8 19
9 20 ### Worker
@@ -77,6 +88,22 @@ Example
77 88 console.log(exception);
78 89 });
79 90
  91 +### Assign an ID for the Worker
  92 +
  93 +Worker ID's identify unique workers for monitoring Gearman.
  94 +
  95 + worker.setWorkerId(id)
  96 +
  97 +Where
  98 +
  99 + * **id** is a string that will act as the name for the worker
  100 +
  101 +Example
  102 +
  103 + worker = new Gearman();
  104 + worker.addServer(); // use default values
  105 + worker.setWorkerId("my_worker");
  106 +
80 107 ### Submit a job
81 108
82 109 client.submitJob(func, payload[, options])
@@ -93,7 +120,7 @@ Possible option values
93 120 * **background** - if set to true, detach the job from the client (complete and error events will not be sent to the client)
94 121 * **priority** - indicates the priority of the job. Possible values "low", "normal" (default) and "high"
95 122
96   -Returns a Gearman Job object with the following events
  123 +Returns a Client Job object with the following events
97 124
98 125 * **created** - when the function is queued by the server (params: handle value)
99 126 * **complete** - when the function returns (params: response data in encoding specified by the options value)
@@ -138,9 +165,9 @@ Where
138 165 * **payload** is the data sent by the client and in the encoding specified with *addFunction*
139 166 * **job** is a Gearman Job object that can be used to send data back
140 167
141   -#### Job object
  168 +#### Worker Job object
142 169
143   -Job object has the following methods
  170 +Worker Job object has the following methods
144 171
145 172 * **complete(response)** - send the result of the function back to the client
146 173 * **error(error)** - throw an exception (and end the job with *failed* status)
19 gearman-connection.js
@@ -16,11 +16,12 @@ function GearmanConnection(server, port){
16 16
17 17 this.queued_jobs = {};
18 18
  19 + this.workerId = null;
  20 +
19 21 this.connected = false;
20 22 this.processing = false;
21 23 this.failed = false;
22 24
23   - this.retries = 0;
24 25 this.remainder = false;
25 26
26 27 this.debug = false;
@@ -140,12 +141,7 @@ GearmanConnection.prototype.processQueue = function(){
140 141
141 142 // if no connection yet, open one
142 143 if(!this.connected){
143   - if(this.retries<5){
144   - this.connect();
145   - }else{
146   - console.log("failed");
147   - this.failed = true;
148   - }
  144 + return this.connect();
149 145 return false;
150 146 }
151 147
@@ -265,15 +261,13 @@ GearmanConnection.prototype.connect = function(){
265 261 this.socket.on("connect", (function(){
266 262 this.connecting = false;
267 263 this.connected = true;
268   - this.retries = 0;
269 264
270 265 if(this.debug){
271 266 console.log("connected!");
272   - }
  267 + }
  268 +
273 269 this.processQueue();
274   -
275 270 }).bind(this));
276   -
277 271
278 272 this.socket.on("end", this.close.bind(this));
279 273 this.socket.on("error", this.close.bind(this));
@@ -298,7 +292,7 @@ GearmanConnection.prototype.close = function(){
298 292 }
299 293 this.connected = false;
300 294 this.connecting = false;
301   - this.retries++;
  295 + this.emit("disconnect");
302 296 }
303 297 }
304 298
@@ -420,6 +414,7 @@ GearmanConnection.prototype.getExceptions = function(callback){
420 414 }
421 415
422 416 GearmanConnection.prototype.setWorkerId = function(id){
  417 + this.workerId = id;
423 418 this.sendCommand({
424 419 type: "SET_CLIENT_ID",
425 420 params: [id]
128 gearnode.js
@@ -10,6 +10,8 @@ function Gearman(){
10 10
11 11 this.function_names = [];
12 12 this.functions = {};
  13 +
  14 + this.workerId = null;
13 15 }
14 16 utillib.inherits(Gearman, EventEmitter);
15 17
@@ -31,7 +33,6 @@ Gearman.prototype.addServer = function(server_name, server_port){
31 33
32 34 this.servers[server_name].connection.on("error", function(err){
33 35 console.log("Error with "+server_name);
34   - //console.log(err.message);
35 36 console.log(err.stack);
36 37 });
37 38
@@ -82,33 +83,6 @@ Gearman.prototype.addServer = function(server_name, server_port){
82 83 this.update(server_name);
83 84 }
84 85
85   -Gearman.prototype.runJob = function(server_name, handle, func_name, payload, uid){
86   - uid = uid || null;
87   - if(this.functions[func_name]){
88   -
89   - var encoding = this.functions[func_name].encoding.toLowerCase() || "buffer";
90   -
91   - switch(encoding){
92   - case "utf-8":
93   - case "ascii":
94   - case "base64":
95   - payload = payload && payload.toString(encoding) || "";
96   - break;
97   - case "number":
98   - payload = Number(payload && payload.toString("ascii") || "") || 0;
99   - break;
100   - case "buffer":
101   - default:
102   - // keep buffer
103   - }
104   -
105   - var job = new Gearman.GearmanWorker(handle, server_name, this);
106   - this.functions[func_name].func(payload, job);
107   - }else{
108   - this.servers[server_name].connection.jobError(handle, "Function "+func_name+" not found");
109   - }
110   -}
111   -
112 86 Gearman.prototype.removeServer = function(server_name){
113 87 var connection, pos;
114 88
@@ -130,6 +104,11 @@ Gearman.prototype.removeServer = function(server_name){
130 104 return true;
131 105 }
132 106
  107 +Gearman.prototype.end = function(){
  108 + for(var i=this.server_names.length-1; i>=0; i--){
  109 + this.removeServer(this.server_names[i]);
  110 + }
  111 +}
133 112
134 113 Gearman.prototype.update = function(server_name){
135 114 if(!server_name){
@@ -139,6 +118,10 @@ Gearman.prototype.update = function(server_name){
139 118 this.function_names.forEach((function(func_name){
140 119 this.register(func_name, server_name);
141 120 }).bind(this));
  121 +
  122 + if(this.workerId){
  123 + this.setWorkerId(server_name, this.workerId);
  124 + }
142 125 }
143 126
144 127 Gearman.prototype.register = function(func_name, server_name){
@@ -172,38 +155,37 @@ Gearman.prototype.unregister = function(func_name, server_name){
172 155 }
173 156 }
174 157
  158 +// WORKER FUNCTIONS
175 159
176   -Gearman.prototype.getExceptions = function(server_name, callback){
177   - var pos;
178   -
179   - if(!callback && typeof server_name =="function"){
180   - callback = server_name;
181   - server_name = null;
182   - }
183   -
184   - if(server_name){
185   - if(this.servers[server_name]){
186   -
187   - this.servers[server_name].connection.getExceptions((function(err, success){
188   - if(callback){
189   - return callback(err, success);
190   - }
191   - if(err){
192   - console.log("Server "+server_name+" responded with error: "+(err.message || err));
193   - }else{
194   - console.log("Exceptions are followed from "+server_name);
195   - }
196   - }).bind(this));
  160 +Gearman.prototype.runJob = function(server_name, handle, func_name, payload, uid){
  161 + uid = uid || null;
  162 + if(this.functions[func_name]){
  163 +
  164 + var encoding = this.functions[func_name].encoding.toLowerCase() || "buffer";
  165 +
  166 + switch(encoding){
  167 + case "utf-8":
  168 + case "ascii":
  169 + case "base64":
  170 + payload = payload && payload.toString(encoding) || "";
  171 + break;
  172 + case "number":
  173 + payload = Number(payload && payload.toString("ascii") || "") || 0;
  174 + break;
  175 + case "buffer":
  176 + default:
  177 + // keep buffer
197 178 }
  179 +
  180 + var job = new Gearman.GearmanWorker(handle, server_name, this);
  181 + this.functions[func_name].func(payload, job);
198 182 }else{
199   - this.server_names.forEach((function(server_name){
200   - if(server_name){
201   - this.getExceptions(server_name, callback);
202   - }
203   - }).bind(this))
  183 + this.servers[server_name].connection.jobError(handle, "Function "+func_name+" not found");
204 184 }
205 185 }
206 186
  187 +
  188 +
207 189 Gearman.prototype.setWorkerId = function(server_name, id){
208 190 var pos;
209 191
@@ -217,10 +199,10 @@ Gearman.prototype.setWorkerId = function(server_name, id){
217 199
218 200 if(server_name){
219 201 if(this.servers[server_name]){
220   -
221 202 this.servers[server_name].connection.setWorkerId(id);
222 203 }
223 204 }else{
  205 + this.workerId = id;
224 206 this.server_names.forEach((function(server_name){
225 207 if(server_name){
226 208 this.setWorkerId(server_name, id);
@@ -253,7 +235,6 @@ Gearman.prototype.addFunction = function(name, encoding, func){
253 235 func: func,
254 236 encoding: encoding || "buffer"
255 237 }
256   - this.function_names.push(name);
257 238 }
258 239
259 240 }
@@ -272,9 +253,36 @@ Gearman.prototype.removeFunction = function(name){
272 253 }
273 254 }
274 255
275   -Gearman.prototype.end = function(){
276   - for(var i=this.server_names.length-1; i>=0; i--){
277   - this.removeServer(this.server_names[i]);
  256 +// CLIENT FUNCTIONS
  257 +
  258 +Gearman.prototype.getExceptions = function(server_name, callback){
  259 + var pos;
  260 +
  261 + if(!callback && typeof server_name =="function"){
  262 + callback = server_name;
  263 + server_name = null;
  264 + }
  265 +
  266 + if(server_name){
  267 + if(this.servers[server_name]){
  268 +
  269 + this.servers[server_name].connection.getExceptions((function(err, success){
  270 + if(callback){
  271 + return callback(err, success);
  272 + }
  273 + if(err){
  274 + console.log("Server "+server_name+" responded with error: "+(err.message || err));
  275 + }else{
  276 + console.log("Exceptions are followed from "+server_name);
  277 + }
  278 + }).bind(this));
  279 + }
  280 + }else{
  281 + this.server_names.forEach((function(server_name){
  282 + if(server_name){
  283 + this.getExceptions(server_name, callback);
  284 + }
  285 + }).bind(this))
278 286 }
279 287 }
280 288
@@ -288,6 +296,8 @@ Gearman.prototype.submitJob = function(func_name, payload, options){
288 296 return new Gearman.GearmanJob(func_name, payload, options, server);
289 297 }
290 298
  299 +
  300 +// WORKER JOB
291 301 Gearman.GearmanJob = function(func_name, payload, options, server){
292 302 EventEmitter.call(this);
293 303
441 tests.js
... ... @@ -0,0 +1,441 @@
  1 +var Gearnode = require("./gearnode"),
  2 + GearmanConnection = require("./gearman-connection"),
  3 + testCase = require('nodeunit').testCase;
  4 +
  5 +
  6 +exports.gearnode_instance = function(test){
  7 + var gearman = new Gearnode();
  8 + test.expect(1);
  9 + test.ok(gearman instanceof Gearnode, "Worker is a Gearnode instance");
  10 + test.done();
  11 +}
  12 +
  13 +// ADD SERVER
  14 +
  15 +exports.server = {
  16 +
  17 + add_one_server: function(test){
  18 + var gearman = new Gearnode();
  19 + gearman.addServer();
  20 +
  21 + test.expect(2);
  22 + test.equal(gearman.server_names.length, 1, "One item in server_names array");
  23 + test.equal(Object.keys(gearman.servers).length, 1, "One item in gearman.servers object");
  24 + test.done();
  25 + },
  26 +
  27 + add_one_server_multiple_times: function(test){
  28 + var gearman = new Gearnode();
  29 + gearman.addServer("localhost");
  30 + gearman.addServer("localhost");
  31 +
  32 + test.expect(2);
  33 + test.equal(gearman.server_names.length, 1, "One item in server_names array");
  34 + test.equal(Object.keys(gearman.servers).length, 1, "One item in gearman.servers object");
  35 + test.done();
  36 + },
  37 +
  38 + add_multiple_servers: function(test){
  39 + var gearman = new Gearnode();
  40 + gearman.addServer("localhost.local");
  41 + gearman.addServer("localhost.lan");
  42 +
  43 + test.expect(2);
  44 + test.equal(gearman.server_names.length, 2, "Two items in server_names array");
  45 + test.equal(Object.keys(gearman.servers).length, 2, "Two items in gearman.servers object");
  46 + test.done();
  47 + },
  48 +
  49 + server_instance: function(test){
  50 + var gearman = new Gearnode();
  51 + gearman.addServer();
  52 +
  53 + test.expect(1);
  54 + test.ok(gearman.servers[gearman.server_names[0]].connection instanceof GearmanConnection, "Connection instance")
  55 + test.done();
  56 + }
  57 +}
  58 +
  59 +// ADD FUNCTIONS
  60 +
  61 +exports.functions = {
  62 +
  63 + add_one_function: function(test){
  64 + var gearman = new Gearnode();
  65 +
  66 + gearman.addFunction("foo", function(){});
  67 +
  68 + test.expect(2);
  69 + test.equal(gearman.function_names.length, 1, "One item in function_names array");
  70 + test.equal(Object.keys(gearman.functions).length, 1, "One item in gearman.functions object");
  71 + test.done();
  72 + },
  73 +
  74 + add_one_function_multiple_times: function(test){
  75 + var gearman = new Gearnode();
  76 +
  77 + gearman.addFunction("foo", function(){});
  78 + gearman.addFunction("foo", function(){});
  79 +
  80 + test.expect(2);
  81 + test.equal(gearman.function_names.length, 1, "One item in function_names array");
  82 + test.equal(Object.keys(gearman.functions).length, 1, "One item in gearman.functions object");
  83 + test.done();
  84 + },
  85 +
  86 + add_multiple_functions: function(test){
  87 + var gearman = new Gearnode();
  88 +
  89 + gearman.addFunction("foo", function(){});
  90 + gearman.addFunction("bar", function(){});
  91 +
  92 + test.expect(2);
  93 + test.equal(gearman.function_names.length, 2, "Two items in function_names array");
  94 + test.equal(Object.keys(gearman.functions).length, 2, "Two items in gearman.functions object");
  95 + test.done();
  96 + },
  97 +
  98 + function_properties: function(test){
  99 + var gearman = new Gearnode();
  100 +
  101 + gearman.addFunction("foo", function(){});
  102 + gearman.addFunction("bar", "string", function(){});
  103 +
  104 + test.expect(6);
  105 + test.equal(gearman.function_names[0], "foo", "Function name for foo");
  106 + test.equal(gearman.function_names[1], "bar", "Function name for bar");
  107 + test.equal(typeof gearman.functions[gearman.function_names[0]].func, "function", "Function instance for foo");
  108 + test.equal(typeof gearman.functions[gearman.function_names[1]].func, "function", "Function instance for bar");
  109 + test.equal(gearman.functions[gearman.function_names[0]].encoding, "buffer", "Function encoding for foo");
  110 + test.equal(gearman.functions[gearman.function_names[1]].encoding, "string", "Function encoding for bar");
  111 + test.done();
  112 + }
  113 +}
  114 +
  115 +// FUNCTIONS AND SERVES
  116 +
  117 +exports.functions_servers = {
  118 +
  119 + add_function_to_existing_server: function(test){
  120 + var gearman = new Gearnode();
  121 +
  122 + gearman.addServer("foo");
  123 + gearman.addFunction("bar", function(){});
  124 +
  125 + test.expect(1);
  126 + test.equal(gearman.servers["foo"].functions.length, 1, "One item in server functions array");
  127 + test.done();
  128 + },
  129 +
  130 + add_function_before_server: function(test){
  131 + var gearman = new Gearnode();
  132 +
  133 + gearman.addFunction("bar", function(){});
  134 + gearman.addServer("foo");
  135 +
  136 + test.expect(1);
  137 + test.equal(gearman.servers["foo"].functions.length, 1, "One item in server functions array");
  138 + test.done();
  139 + }
  140 +}
  141 +
  142 +// WORKER ID
  143 +
  144 +exports.worker_id = {
  145 +
  146 + set_worker_id: function(test){
  147 + var gearman = new Gearnode();
  148 +
  149 + gearman.setWorkerId("bar");
  150 +
  151 + test.expect(1);
  152 + test.equal(gearman.workerId, "bar", "Worker ID");
  153 + test.done();
  154 + },
  155 +
  156 + set_worker_id_to_servers: function(test){
  157 + var gearman = new Gearnode();
  158 +
  159 + gearman.addServer("foo");
  160 + gearman.addServer("bar");
  161 +
  162 + gearman.setWorkerId("baz");
  163 +
  164 + test.expect(2);
  165 + test.equal(gearman.servers["foo"].connection.workerId, "baz", "Worker ID");
  166 + test.equal(gearman.servers["bar"].connection.workerId, "baz", "Worker ID");
  167 + test.done();
  168 + },
  169 +
  170 + set_worker_id_before_server: function(test){
  171 + var gearman = new Gearnode();
  172 +
  173 + gearman.addServer("foo");
  174 + gearman.setWorkerId("baz");
  175 + gearman.addServer("bar");
  176 +
  177 + test.expect(2);
  178 + test.equal(gearman.servers["foo"].connection.workerId, "baz", "Worker ID");
  179 + test.equal(gearman.servers["bar"].connection.workerId, "baz", "Worker ID");
  180 + test.done();
  181 + }
  182 +}
  183 +
  184 +module.exports.worker = testCase({
  185 + setUp: function (callback) {
  186 + this.worker = new Gearnode();
  187 + this.worker.addServer("localhost",7003);
  188 +
  189 + this.client = new Gearnode();
  190 + this.client.addServer("localhost",7003);
  191 +
  192 + this.worker.addFunction("upper", function(payload, job){
  193 + job.complete(payload.toString("utf-8").toUpperCase());
  194 + });
  195 +
  196 + this.worker.addFunction("upper_utf8","utf-8", function(payload, job){
  197 + job.complete(payload.toUpperCase());
  198 + });
  199 +
  200 + this.worker.addFunction("upper_base64","base64", function(payload, job){
  201 + job.complete(new Buffer(payload, "base64").toString("utf-8").toUpperCase());
  202 + });
  203 +
  204 + this.worker.addFunction("getexception",function(payload, job){
  205 + job.error(new Error("Error happened"));
  206 + });
  207 +
  208 + this.worker.addFunction("partial",function(payload, job){
  209 + var i=0;
  210 + job.data(i++);
  211 + job.data(i++);
  212 + job.data(i++);
  213 + job.complete("ready");
  214 + });
  215 +
  216 + this.worker.addFunction("getwarning",function(payload, job){
  217 + job.warning("foo");
  218 + job.complete("bar");
  219 + });
  220 +
  221 + this.worker.addFunction("getfail",function(payload, job){
  222 + job.fail();
  223 + });
  224 +
  225 + callback();
  226 + },
  227 +
  228 + tearDown: function (callback) {
  229 + // clean up
  230 + callback();
  231 + },
  232 +
  233 + test_upper: function (test) {
  234 +
  235 + test.expect(1);
  236 +
  237 + var job = this.client.submitJob("upper","test");
  238 +
  239 + job.on("complete", function(data){
  240 + test.equal(data.toString("utf-8"), "TEST", "Function success");
  241 + test.done();
  242 + });
  243 +
  244 + job.on("fail", function(){
  245 + test.ok(false, "Function failed");
  246 + test.done();
  247 + });
  248 + job.on("error", function(){
  249 + test.ok(false, "Function failed with error");
  250 + test.done();
  251 + });
  252 + },
  253 +
  254 + test_upper_utf8: function (test) {
  255 +
  256 + test.expect(1);
  257 +
  258 + var job = this.client.submitJob("upper_utf8","test");
  259 +
  260 + job.on("complete", function(data){
  261 + test.equal(data.toString("utf-8"), "TEST", "Function success");
  262 + test.done();
  263 + });
  264 +
  265 + job.on("fail", function(){
  266 + test.ok(false, "Function failed");
  267 + test.done();
  268 + });
  269 + job.on("error", function(){
  270 + test.ok(false, "Function failed with error");
  271 + test.done();
  272 + });
  273 + },
  274 +
  275 + test_upper_base64: function (test) {
  276 +
  277 + test.expect(1);
  278 +
  279 + var job = this.client.submitJob("upper_base64","test");
  280 +
  281 + job.on("complete", function(data){
  282 + test.equal(data.toString("utf-8"), "TEST", "Function success");
  283 + test.done();
  284 + });
  285 +
  286 + job.on("fail", function(){
  287 + test.ok(false, "Function failed");
  288 + test.done();
  289 + });
  290 + job.on("error", function(){
  291 + test.ok(false, "Function failed with error");
  292 + test.done();
  293 + });
  294 + },
  295 +
  296 + test_upper_expect_utf8: function (test) {
  297 +
  298 + test.expect(1);
  299 +
  300 + var job = this.client.submitJob("upper","test", {encoding:"utf-8"});
  301 +
  302 + job.on("complete", function(data){
  303 + test.equal(data, "TEST", "Function success");
  304 + test.done();
  305 + });
  306 +
  307 + job.on("fail", function(){
  308 + test.ok(false, "Function failed");
  309 + test.done();
  310 + });
  311 + job.on("error", function(){
  312 + test.ok(false, "Function failed with error");
  313 + test.done();
  314 + });
  315 + },
  316 +
  317 + test_upper_expect_base64: function (test) {
  318 +
  319 + test.expect(1);
  320 +
  321 + var job = this.client.submitJob("upper","test", {encoding:"base64"});
  322 +
  323 + job.on("complete", function(data){
  324 + test.equal(data, new Buffer("TEST","utf-8").toString("base64"), "Function success");
  325 + test.done();
  326 + });
  327 +
  328 + job.on("fail", function(){
  329 + test.ok(false, "Function failed");
  330 + test.done();
  331 + });
  332 + job.on("error", function(){
  333 + test.ok(false, "Function failed with error");
  334 + test.done();
  335 + });
  336 + },
  337 +
  338 + getExceptions: function(test){
  339 + test.expect(2);
  340 + this.client.getExceptions((function(err, success){
  341 + test.ok(success,"Listening for exceptions");
  342 +
  343 + var job = this.client.submitJob("getexception","test");
  344 +
  345 + job.on("complete", function(data){
  346 + test.ok("false","No exceptions");
  347 + test.done();
  348 + });
  349 +
  350 + job.on("fail", function(){
  351 + test.ok("false","No exceptions");
  352 + test.done();
  353 + });
  354 +
  355 + job.on("error", function(){
  356 + test.ok(true, "Function failed with error");
  357 + test.done();
  358 + });
  359 +
  360 + }).bind(this));
  361 + },
  362 +
  363 + test_partial_data: function(test){
  364 + test.expect(4);
  365 +
  366 + var job = this.client.submitJob("partial", "test", {encoding:"utf-8"}),
  367 + i = 0;
  368 +
  369 + job.on("complete", function(data){
  370 + test.equal(data, "ready", "Function success");
  371 + test.done();
  372 + });
  373 +
  374 + job.on("fail", function(){
  375 + test.ok(false, "Function failed");
  376 + test.done();
  377 + });
  378 +
  379 + job.on("error", function(){
  380 + test.ok(false, "Function failed with error");
  381 + test.done();
  382 + });
  383 +
  384 + job.on("data", function(data){
  385 + test.equal(String(i++), data, "Function part OK");
  386 + test.done();
  387 + });
  388 + },
  389 +
  390 + test_warning: function (test) {
  391 +
  392 + test.expect(2);
  393 +
  394 + var job = this.client.submitJob("getwarning","test", {encoding:"utf-8"});
  395 +
  396 + job.on("complete", function(data){
  397 + test.equal(data, "bar", "Completed");
  398 + test.done();
  399 + });
  400 +
  401 + job.on("warning", function(data){
  402 + test.equal(data, "foo", "Function warning");
  403 + test.done();
  404 + });
  405 +
  406 + job.on("fail", function(){
  407 + test.ok(false, "Function failed");
  408 + test.done();
  409 + });
  410 +
  411 + job.on("error", function(){
  412 + test.ok(false, "Function failed with error");
  413 + test.done();
  414 + });
  415 + },
  416 +
  417 + test_fail: function (test) {
  418 +
  419 + test.expect(1);
  420 +
  421 + var job = this.client.submitJob("getfail","test", {encoding:"utf-8"});
  422 +
  423 + job.on("complete", function(data){
  424 + test.ok(false, "SHould not complete");
  425 + test.done();
  426 + });
  427 +
  428 + job.on("fail", function(){
  429 + test.ok(true, "Function failed");
  430 + test.done();
  431 + });
  432 +
  433 + job.on("error", function(){
  434 + test.ok(false, "Function failed with error");
  435 + test.done();
  436 + });
  437 + }
  438 +});
  439 +
  440 +
  441 +

0 comments on commit 29479d9

Please sign in to comment.
Something went wrong with that request. Please try again.