Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
veny committed Jun 27, 2015
1 parent 741b177 commit 1fdb141
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 3 additions & 0 deletions lib/gearmanode/job-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ var JobServer = exports.JobServer = function (options) {
this.connected = false;
this.jobsWaiting4Created = []; // submited jobs waiting for JOB_CREATED response
this.wrongDisconnectAt = 0;
this.failedConnectionCount = 0;
};

// inheritance
Expand Down Expand Up @@ -99,6 +100,7 @@ JobServer.prototype.connect = function (callback) {
self.socket.setKeepAlive(true);
self.connected = true;
self.wrongDisconnectAt = 0;
self.failedConnectionCount = 0
self.emit('ConnectInternal140319214558');
self.clientOrWorker.emit('socketConnect', self.getUid()); // trigger event
JobServer.logger.log('debug', 'connection established, uid=%s', self.getUid());
Expand Down Expand Up @@ -183,6 +185,7 @@ JobServer.prototype.disconnect = function (err) {
this.removeAllListeners();
if (err !== undefined) {
this.wrongDisconnectAt = new Date();
this.failedConnectionCount += 1;
}

// close jobs waiting for packet JOB_CREATED
Expand Down
6 changes: 5 additions & 1 deletion test/test-job-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ describe('JobServer', function() {
should.not.exist(js.clientOrWorker);
js.jobsWaiting4Created.length.should.equal(0);
js.getUid().should.equal('localhost:4730');
should.exist(js.wrongDisconnectAt);
js.wrongDisconnectAt.should.be.equal(0);
js.failedConnectionCount.should.be.equal(0);
})
it('should return error when missing mandatory options', function() {
js = new JobServer();
Expand All @@ -45,6 +45,7 @@ describe('JobServer', function() {
js.connect(function(err) {
js.connected.should.be.true;
js.wrongDisconnectAt.should.be.equal(0);
js.failedConnectionCount.should.be.equal(0);
should.exist(js.socket);
js.socket.should.be.an.instanceof(net.Socket);
done();
Expand Down Expand Up @@ -79,6 +80,7 @@ describe('JobServer', function() {
err.code.should.be.equal('ECONNREFUSED');
js.connected.should.be.false;
js.wrongDisconnectAt.should.be.greaterThan(0);
js.failedConnectionCount.should.be.greaterThan(0);
should.not.exist(js.socket);
done();
})
Expand Down Expand Up @@ -113,6 +115,7 @@ describe('JobServer', function() {
js.disconnect();
js.connected.should.be.false;
js.wrongDisconnectAt.should.be.equal(0);
js.failedConnectionCount.should.be.equal(0);
should.not.exist(js.socket);
should.exist(js.clientOrWorker);
js.jobsWaiting4Created.length.should.equal(0);
Expand All @@ -124,6 +127,7 @@ describe('JobServer', function() {
should.not.exist(err);
js.disconnect(true); // true => simulate an error object
js.wrongDisconnectAt.should.be.greaterThan(0);
js.failedConnectionCount.should.be.greaterThan(0);
done();
})
})
Expand Down

0 comments on commit 1fdb141

Please sign in to comment.