diff --git a/packages/matter-node.js/test/IntegrationTest.ts b/packages/matter-node.js/test/IntegrationTest.ts index 0d40ecc5fc..35ee95ca78 100644 --- a/packages/matter-node.js/test/IntegrationTest.ts +++ b/packages/matter-node.js/test/IntegrationTest.ts @@ -1505,29 +1505,15 @@ describe("Integration Test", () => { }); after(async () => { - const promise = mdnsBroadcaster.expireAllAnnouncements(matterPort); - - await MockTime.yield(); - await MockTime.yield(); - await MockTime.yield(); - await MockTime.yield(); - await MockTime.advance(150); - await MockTime.advance(150); - await MockTime.yield(); - - await MockTime.yield(); - await MockTime.yield(); - await MockTime.yield(); - await MockTime.yield(); - await MockTime.advance(150); - await MockTime.advance(150); - await MockTime.yield(); - - await promise; + // For closing all down we need to use the real Time implementation + const mockTimeInstance = Time.get(); + Time.get = singleton(() => new TimeNode()); await matterServer.close(); await matterClient.close(); await fakeControllerStorage.close(); await fakeServerStorage.close(); + + Time.get = () => mockTimeInstance; }); }); diff --git a/packages/matter.js/src/MatterDevice.ts b/packages/matter.js/src/MatterDevice.ts index 7a98465b99..dfb5b18e67 100644 --- a/packages/matter.js/src/MatterDevice.ts +++ b/packages/matter.js/src/MatterDevice.ts @@ -148,29 +148,23 @@ export class MatterDevice { } const fabrics = this.fabricManager.getFabrics(); if (fabrics.length) { - const fabricsToAnnounce: Fabric[] = []; + let fabricsToAnnounce = 0; for (const fabric of fabrics) { const session = this.sessionManager.getSessionForNode(fabric, fabric.rootNodeId); if ( - session !== undefined && - session.isSecure() && - (session as SecureSession).numberOfActiveSubscriptions > 0 + session === undefined || + !session.isSecure() || + (session as SecureSession).numberOfActiveSubscriptions === 0 ) { - // We have a session, no need to re-announce - logger.debug( - "Skipping announce for fabric", - fabric.fabricId, - "because we have a session with active subscriptions", - session.getId(), - ); - continue; + fabricsToAnnounce++; + logger.debug("Announcing", Logger.dict({ fabric: fabric.fabricId })); } - logger.debug("Announcing", Logger.dict({ fabric: fabric.fabricId })); - fabricsToAnnounce.push(fabric); } for (const broadcaster of this.broadcasters) { - await broadcaster.setFabrics(fabricsToAnnounce); - await broadcaster.announce(); + await broadcaster.setFabrics(fabrics); + if (fabricsToAnnounce > 0) { + await broadcaster.announce(); + } } } else { // No fabric paired yet, so announce as "ready for commissioning"