Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'dev'

  • Loading branch information...
commit b9ea6cb4e4686d6f7cf4d9ebaea6fe4259178543 2 parents a89d85b + db930bb
Peter Magnusson authored
Showing with 42 additions and 20 deletions.
  1. +20 −13 mcquery.js
  2. +22 −7 test/test.js
33 mcquery.js
View
@@ -57,28 +57,35 @@ var Query = module.exports = function Query(host, port){
this.connect = function(callback){
if (! self.online){
socket.on('listening', function(){
- doHandshake();
- self.online=true;
+ process.nextTick(function(){
+ self.doHandshake(callback);
+ self.online=true;
+ });
+
});
socket.bind();
}
else {
- doHandshake();
+ self.doHandshake(callback);
}
- function doHandshake(){
- log.debug("doing handshake");
- self.idToken = generateToken();
- self.send(CHALLENGE_TYPE, function(err, res){
- if(err){callback(err); return;}
- log.debug("challengeToken=", res.challengeToken);
- self.challengeToken = res.challengeToken;
- callback(null, self);
- });
- }
+
};//end startSession
+
+ this.doHandshake = function (callback){
+ callback = callback || function(){};
+ log.debug("doing handshake");
+ self.idToken = generateToken();
+ self.send(CHALLENGE_TYPE, function(err, res){
+ if(err){callback(err); return;}
+ log.debug("challengeToken=", res.challengeToken);
+ self.challengeToken = res.challengeToken;
+ callback(null, self);
+ });
+ }
+
/**
* Request basic stat information using session
* @param {Object} a session object created by startSession
29 test/test.js
View
@@ -24,8 +24,7 @@ var global_session;
describe('mcquery', function() {
after(function(done){
- //global_query.close();
- console.log("closing");
+ global_query.close();
done();
});
@@ -53,6 +52,16 @@ describe('mcquery', function() {
global_session.idToken.should.equal(global_session.idToken & 0x0F0F0F0F);
});
+ it('should be able to do an .doHandshake', function(done){
+ var oldChallenge = global_session.challengeToken;
+ global_query.doHandshake(function(err, session){
+ should.not.exist(err);
+ session.challengeToken.should.not.be.equal(oldChallenge);
+ done();
+ });
+
+ });
+
describe('.basic_stat(err, result)', function(){
var result, err;
before(function(done){
@@ -88,11 +97,17 @@ describe('mcquery', function() {
describe('.full_stat(err, result)', function(){
var err, result;
before(function(done){
- global_query.full_stat(function(er, stat){
- err = er;
- result = stat;
- done();
- })
+ global_query.doHandshake(function(er, session){
+ should.not.exist(er);
+
+ global_query.full_stat(function(er, stat){
+ err = er;
+ result = stat;
+ done();
+ });
+ });
+
+
});
it('err should be null', function(){
Please sign in to comment.
Something went wrong with that request. Please try again.