Skip to content

Commit dbf64c8

Browse files
dgp1130atscott
authored andcommitted
test(core): fix AI tools test flake
This test flakes occasionally because it is called in production when a platform is created and unregistered when a platform is destroyed. However, not all tests properly clean up their platforms, meaning we can accidentally leak platforms between tests. If this happens, we end up have an event listener created from the production code path and a second event listener from the test. When the test emits the event, both listeners respond and it causes too many responses which fails the test. Ideally, all tests would clean up the platforms correctly, but this seems difficult to guarantee for all Angular tests and is likely to break over time. The simplest solution is just destroy any leaked platform before the test starts. It's a bit elegant, but the safest option. (cherry picked from commit 492e3a2)
1 parent 045bb73 commit dbf64c8

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

packages/core/test/debug/ai/registration_spec.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,17 @@
99
import {signalGraphTool} from '../../../src/debug/ai/signal_graph';
1010
import {registerAiTools} from '../../../src/debug/ai';
1111
import {DevtoolsToolDiscoveryEvent} from '../../../src/debug/ai/tool_definitions';
12+
import {destroyPlatform} from '../../../src/core';
1213

1314
describe('registration', () => {
15+
beforeEach(() => {
16+
// Destroy any pre-existing platform created by other tests which wasn't properly destroyed.
17+
// Creating a platform calls `registerAiTools` in its production code path and unregisters when the platform is destroyed.
18+
// If a platform leaks between tests, then there is an extra active AI tools event listener which can break these tests.
19+
// The easiest solution is to just destroy any leaked platforms to make sure the environment is stable before we run.
20+
destroyPlatform();
21+
});
22+
1423
describe('registerAiTools', () => {
1524
it('should register the tools', () => {
1625
const unregister = registerAiTools();

0 commit comments

Comments
 (0)