Clear node context on close

Fixes #870
This commit is contained in:
Nick O'Leary 2016-06-11 22:53:27 +01:00
parent 7302ac5871
commit 4dc9c7714c
3 changed files with 22 additions and 3 deletions

View File

@ -1,5 +1,5 @@
/**
* Copyright 2014, 2015 IBM Corp.
* Copyright 2014, 2016 IBM Corp.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -99,8 +99,15 @@ Node.prototype.close = function() {
}
}
if (promises.length > 0) {
return when.settle(promises);
return when.settle(promises).then(function() {
if (this._context) {
context.delete(this._alias||this.id,this.z);
}
});
} else {
if (this._context) {
context.delete(this._alias||this.id,this.z);
}
return;
}
};

View File

@ -1,5 +1,5 @@
/**
* Copyright 2015 IBM Corp.
* Copyright 2015, 2016 IBM Corp.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -76,5 +76,6 @@ module.exports = {
globalContext = createContext("global",settings.functionGlobalContext || {});
},
get: getContext,
delete: deleteContext,
clean:clean
};

View File

@ -108,4 +108,15 @@ describe('context', function() {
context2.global.get("foo").should.eql("test");
});
it('deletes context',function() {
var context = Context.get("1","flowA");
should.not.exist(context.get("foo"));
context.set("foo","abc");
context.get("foo").should.eql("abc");
Context.delete("1","flowA");
context = Context.get("1","flowA");
should.not.exist(context.get("foo"));
})
});