Skip to content
Permalink
Browse files

test: refactor tick objects prune function

PR-URL: #26163
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information...
AllanEd authored and addaleax committed Feb 17, 2019
1 parent 6f9ab5e commit 69154e405c9ad3299e06adfbdcd5ee9e330aa01e
Showing with 23 additions and 15 deletions.
  1. +23 −15 test/async-hooks/verify-graph.js
@@ -17,29 +17,37 @@ function pruneTickObjects(activities) {
// Remove one TickObject on each pass until none is left anymore
// not super efficient, but simplest especially to handle
// multiple TickObjects in a row
let foundTickObject = true;
const tickObject = {
found: true,
index: null,
data: null
};

while (foundTickObject) {
foundTickObject = false;
let tickObjectIdx = -1;
while (tickObject.found) {
for (let i = 0; i < activities.length; i++) {
if (activities[i].type !== 'TickObject') continue;
tickObjectIdx = i;
break;
if (activities[i].type === 'TickObject') {
tickObject.index = i;
break;
} else if (i + 1 === activities.length) {
tickObject.found = false;
}
}

if (tickObjectIdx >= 0) {
foundTickObject = true;

if (tickObject.found) {
// Point all triggerAsyncIds that point to the tickObject
// to its triggerAsyncId and finally remove it from the activities
const tickObject = activities[tickObjectIdx];
const newTriggerId = tickObject.triggerAsyncId;
const oldTriggerId = tickObject.uid;
tickObject.data = activities[tickObject.index];
const triggerId = {
new: tickObject.data.triggerAsyncId,
old: tickObject.data.uid
};

activities.forEach(function repointTriggerId(x) {
if (x.triggerAsyncId === oldTriggerId) x.triggerAsyncId = newTriggerId;
if (x.triggerAsyncId === triggerId.old)
x.triggerAsyncId = triggerId.new;
});
activities.splice(tickObjectIdx, 1);

activities.splice(tickObject.index, 1);
}
}
return activities;

0 comments on commit 69154e4

Please sign in to comment.
You can’t perform that action at this time.