Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
test: refactor tick objects prune function
  • Loading branch information
asattelmaier committed Feb 17, 2019
commit a00b0c7f25468ba6d0b2e19788c23775e0bef123
38 changes: 23 additions & 15 deletions test/async-hooks/verify-graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down