Skip to content

Commit 69154e4

Browse files
asattelmaieraddaleax
authored andcommitted
test: refactor tick objects prune function
PR-URL: #26163 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 6f9ab5e commit 69154e4

File tree

1 file changed

+23
-15
lines changed

1 file changed

+23
-15
lines changed

test/async-hooks/verify-graph.js

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,29 +17,37 @@ function pruneTickObjects(activities) {
1717
// Remove one TickObject on each pass until none is left anymore
1818
// not super efficient, but simplest especially to handle
1919
// multiple TickObjects in a row
20-
let foundTickObject = true;
20+
const tickObject = {
21+
found: true,
22+
index: null,
23+
data: null
24+
};
2125

22-
while (foundTickObject) {
23-
foundTickObject = false;
24-
let tickObjectIdx = -1;
26+
while (tickObject.found) {
2527
for (let i = 0; i < activities.length; i++) {
26-
if (activities[i].type !== 'TickObject') continue;
27-
tickObjectIdx = i;
28-
break;
28+
if (activities[i].type === 'TickObject') {
29+
tickObject.index = i;
30+
break;
31+
} else if (i + 1 === activities.length) {
32+
tickObject.found = false;
33+
}
2934
}
3035

31-
if (tickObjectIdx >= 0) {
32-
foundTickObject = true;
33-
36+
if (tickObject.found) {
3437
// Point all triggerAsyncIds that point to the tickObject
3538
// to its triggerAsyncId and finally remove it from the activities
36-
const tickObject = activities[tickObjectIdx];
37-
const newTriggerId = tickObject.triggerAsyncId;
38-
const oldTriggerId = tickObject.uid;
39+
tickObject.data = activities[tickObject.index];
40+
const triggerId = {
41+
new: tickObject.data.triggerAsyncId,
42+
old: tickObject.data.uid
43+
};
44+
3945
activities.forEach(function repointTriggerId(x) {
40-
if (x.triggerAsyncId === oldTriggerId) x.triggerAsyncId = newTriggerId;
46+
if (x.triggerAsyncId === triggerId.old)
47+
x.triggerAsyncId = triggerId.new;
4148
});
42-
activities.splice(tickObjectIdx, 1);
49+
50+
activities.splice(tickObject.index, 1);
4351
}
4452
}
4553
return activities;

0 commit comments

Comments
 (0)