Skip to content

Commit

Permalink
loop prevention
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderkirtzel committed Dec 18, 2024
1 parent f217c65 commit c4196a4
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .changeset/unlucky-otters-scream.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@elbwalker/walker.js': minor
'@elbwalker/source-node': minor
---

loop prevention [#484](https://github.com/elbwalker/walkerOS/issues/484)
16 changes: 16 additions & 0 deletions packages/sources/node/src/__tests__/destination.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -433,4 +433,20 @@ describe('Destination', () => {
// timing: 0, // @TODO should be set to default type
});
});

test('loop prevention', async () => {
mockDestination.type = 'foo';
const { elb } = getSource({
destinations: { mockDestination },
});

await elb({ event: 'e a' });
await elb({ event: 'e a', source: { type: 'another one' } });
expect(mockPush).toHaveBeenCalledTimes(2);

jest.clearAllMocks();
await elb({ event: 'e a', source: { type: 'foo' } });

expect(mockPush).toHaveBeenCalledTimes(0);
});
});
4 changes: 4 additions & 0 deletions packages/sources/node/src/lib/destination.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ export async function destinationPush(
}
}

// Prevent recursive loops between sources and destinations
if (isDefined(destination.type) && destination.type === event.source.type)
return false;

const options = { data, instance };

if (eventMapping?.batch && destination.pushBatch) {
Expand Down

0 comments on commit c4196a4

Please sign in to comment.