-
-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Return wrong context in promise chain #28
Comments
@tunv-pnc , did you find a solution to this? kindly share if you did. |
It is possible that you are using a middleware that is not hooked with a CLS compatible promise library. This is a major drawback in using CLS; you need to know all your dependencies that are called in the promise chain and middlewares support CLS. |
@tunv-pnc it('middleware set request-id concurrency', function (done) {
// ARRANGE
const app = express();
app.use(httpContext.middleware);
const mw = (req,res,next)=>{
httpContext.set("request-id",req.header("request-id"));
next();
}
app.use(mw);
app.get('/test', async (req, res) => {
const delay = new Number(req.query.delay);
await new Promise(resolve => setTimeout(resolve, delay)).then(()=>{
res.status(200).json({
value: httpContext.get("request-id")
});
});
});
const sut = supertest(app);
const request1 = '1';
const request2 = '2';
// ACT
sut.get('/test').set("request-id",request1).query({ delay: 100}).end((err, res) => {
// ASSERT
assert.equal(res.body.value, request1);
done();
});
sut.get('/test').set("request-id",request2).query({ delay: 50}).end((err, res) => {
// ASSERT
assert.equal(res.body.value, request2);
});
}); |
@skonves Hi,Can I make pull request this unit test to this repository?:) |
I'm using express-http-context to store request-id(generate each time new request arrived automatically) and get request-id anytime, anywhere I want.
In normal case its working fine but if I get context in promise chain it always return context of the first request. Please help me how to always get context of current request.
Thanks a lot!
The text was updated successfully, but these errors were encountered: