Skip to content

Commit

Permalink
fix: traceId
Browse files Browse the repository at this point in the history
  • Loading branch information
zetxx committed Jun 8, 2022
1 parent e1ad0d4 commit e7cb896
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
11 changes: 8 additions & 3 deletions lib/requests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ const {
ForceDestroy
} = require('./errors');

let cc = 0;
let traceIdCounter = 0;

const createRequest = ({
timeout,
match,
Expand All @@ -13,10 +14,12 @@ const createRequest = ({
config = {},
counter,
tag,
traceId,
waitTime
}) => {
const request = {
tag,
traceId,
idx: counter,
// consist of previous request meta that needs to be matched against
match,
Expand Down Expand Up @@ -75,7 +78,8 @@ const Request = ({
meta: {
method,
direction,
config
config,
traceId = ++traceIdCounter
} = {}
} = {},
timeout
Expand All @@ -88,6 +92,7 @@ const Request = ({
direction,
config,
counter,
traceId,
tag,
waitTime
});
Expand Down Expand Up @@ -128,4 +133,4 @@ const Request = ({
return o;
};

module.exports = Request;
module.exports = Request;
8 changes: 7 additions & 1 deletion tests/unit/test.requests.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,20 @@ tap.test('Request', async(t) => {
const rq = reqPool.add({
timeout: (e) => e,
packet: {
match: {idx: ++idx, tag: tag1}
match: {idx: ++idx, tag: tag1},
meta: {traceId: -1}
}
});
tt.same(
rq.idx > 0,
true,
'index should be greater than 0'
);
tt.same(
rq.traceId,
-1,
'trace id should be same as passed'
);
tt.same(
rq.config,
{waitTime: defaultWaitTime},
Expand Down

0 comments on commit e7cb896

Please sign in to comment.