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,28 +65,46 @@ 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() {
return (my_name || my_atom > 99);
}, },
function(cb) { function(cb) {
self.X.GetAtomName(atom, cb); if (self.X.atom_names[my_atom]) {
return cb();
} }
],
function(err, results) { self.X.GetAtomName(my_atom, function(err, name) {
should.not.exist(err); should.not.exist(err);
results[0].should.equal(atom); if (name && name !== '') {
results[1].should.equal('My testing atom'); my_name = name;
sinon.assert.calledOnce(self.spy); } 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(); done();
});
} }
); );
}); });
});
after(function(done) { after(function(done) {
this.X.pack_stream.flush.restore(); this.X.pack_stream.flush.restore();