Fix GetAtomName

- We were not catching the atoms.
- We were leaking the Client.pending_atoms object.
- Fix test so it does what it was supposed to do.
This commit is contained in:
Santiago Gimeno 2013-10-28 16:46:32 +01:00
parent 10dfbf9a53
commit 951564b0d1
2 changed files with 48 additions and 22 deletions

View file

@ -365,10 +365,18 @@ module.exports = {
GetAtomName: [ GetAtomName: [
[ 'CxSL', [17, 2] ], [ 'CxSL', [17, 2] ],
function(buf) { function(buf, seq_num) {
var nameLen = buf.unpack('S')[0]; var nameLen = buf.unpack('S')[0];
// Atom value starting from 24th byte in the buffer // Atom value starting from 24th byte in the buffer
return buf.unpackString(nameLen, 24); var name = buf.unpackString(nameLen, 24);
var pending_atom = this.pending_atoms[seq_num];
if (!this.atoms[pending_atom]) {
this.atom_names[pending_atom] = name;
this.atoms[name] = pending_atom;
}
delete this.pending_atoms[seq_num];
return name;
} }
], ],

View file

@ -65,27 +65,45 @@ describe('Atoms and atom names cache', function() {
it('should be used after the first request for non-std atom_names', function(done) { it('should be used after the first request for non-std atom_names', function(done) {
var self = this; var self = this;
this.X.InternAtom(false, 'My testing atom', function(err, atom) { var my_name;
should.not.exist(err); /*
sinon.assert.calledOnce(self.spy); * First get an atom defined in the server greater than 68 (WM_TRANSIENT_FOR) and less than 100
async.parallel( * and not already cached
[ */
function(cb) { var my_atom = 69;
self.X.InternAtom(true, 'My testing atom', cb); async.until(
}, function() {
function(cb) { return (my_name || my_atom > 99);
self.X.GetAtomName(atom, cb); },
} function(cb) {
], if (self.X.atom_names[my_atom]) {
function(err, results) { return cb();
should.not.exist(err);
results[0].should.equal(atom);
results[1].should.equal('My testing atom');
sinon.assert.calledOnce(self.spy);
done();
} }
);
}); self.X.GetAtomName(my_atom, function(err, name) {
should.not.exist(err);
if (name && name !== '') {
my_name = name;
} else {
++ my_atom;
}
cb();
});
},
function(err) {
should.not.exist(err);
should.exist(my_name);
self.spy.reset();
self.X.InternAtom(true, my_name, function(err, atom) {
should.not.exist(err);
my_atom.should.equal(atom);
sinon.assert.notCalled(self.spy);
Object.keys(self.X.pending_atoms).should.be.empty;
done();
});
}
);
}); });
after(function(done) { after(function(done) {