From 23df30453513692129da640225bf2ddb9f14179b Mon Sep 17 00:00:00 2001 From: Phil Kunz Date: Tue, 17 Sep 2019 15:40:54 +0200 Subject: [PATCH] fix(core): update --- test/test.ts | 11 +++++---- ts/smartuniverse.classes.universe.ts | 1 + ts/smartuniverse.classes.universecache.ts | 2 +- ts/smartuniverse.classes.universechannel.ts | 2 +- ts/smartuniverse.classes.universemessage.ts | 25 +++++++++------------ 5 files changed, 20 insertions(+), 21 deletions(-) diff --git a/test/test.ts b/test/test.ts index 20ba795..8c781e9 100644 --- a/test/test.ts +++ b/test/test.ts @@ -77,8 +77,10 @@ tap.test('should receive a message correctly', async (tools) => { const testChannel = testClientUniverse.getChannel(testChannelData.channelName); const testChannel2 = testClientUniverse2.getChannel(testChannelData.channelName); const subscription = testChannel2.subscribe(messageArg => { - console.log('Yay##########'); - done.resolve(); + if (messageArg.messageText === 'hellothere') { + console.log('Yay##########'); + done.resolve(); + } }); await testChannel.sendMessage({ messageText: 'hellothere' @@ -117,11 +119,12 @@ tap.test('ReactionRequest and ReactionResponse should work', async () => { console.log(result); }); -tap.test('should disconnect the client correctly', async () => { +tap.test('should disconnect the client correctly', async (tools) => { await testClientUniverse.stop(); + await testClientUniverse2.stop(); }); -tap.test('should end the server correctly', async tools => { +tap.test('should end the server correctly', async (tools) => { await testUniverse.stopServer(); }); diff --git a/ts/smartuniverse.classes.universe.ts b/ts/smartuniverse.classes.universe.ts index 5d30c7a..246ea60 100644 --- a/ts/smartuniverse.classes.universe.ts +++ b/ts/smartuniverse.classes.universe.ts @@ -178,6 +178,7 @@ export class Universe { * stop everything */ public async stopServer() { + console.log('hi'); await this.smartsocket.stop(); if (!this.options.externalServer) { await this.smartexpressServer.stop(); diff --git a/ts/smartuniverse.classes.universecache.ts b/ts/smartuniverse.classes.universecache.ts index e9efc71..eada649 100644 --- a/ts/smartuniverse.classes.universecache.ts +++ b/ts/smartuniverse.classes.universecache.ts @@ -19,7 +19,7 @@ export class UniverseCache { // INSTANCE // ======== public standardMessageExpiry: number; - public destructionTime: number = 60000; + public destructionTime: number = 10000; /** * stores messages for this instance diff --git a/ts/smartuniverse.classes.universechannel.ts b/ts/smartuniverse.classes.universechannel.ts index 08311b1..b4ee52d 100644 --- a/ts/smartuniverse.classes.universechannel.ts +++ b/ts/smartuniverse.classes.universechannel.ts @@ -163,6 +163,6 @@ export class UniverseChannel { passphrase: this.passphrase, timestamp: Date.now() }); - this.push(messageToSend); + this.universeRef.universeCache.addMessage(messageToSend); } } diff --git a/ts/smartuniverse.classes.universemessage.ts b/ts/smartuniverse.classes.universemessage.ts index 707a75c..630d8ff 100644 --- a/ts/smartuniverse.classes.universemessage.ts +++ b/ts/smartuniverse.classes.universemessage.ts @@ -64,7 +64,7 @@ export class UniverseMessage implements interfaces.IUniverseMessage { this.passphrase = messageDescriptor.passphrase; this.payload = messageDescriptor.payload; // prevent memory issues - this.fallBackDestruction(); + this.setDestructionTimer(); } public setUniverseCache(universeCacheArg: UniverseCache) { @@ -73,17 +73,23 @@ export class UniverseMessage implements interfaces.IUniverseMessage { public setTargetChannel() {} - public setDestructionTimer(selfdestructAfterArg: number) { + public setDestructionTimer(selfdestructAfterArg?: number) { if (selfdestructAfterArg) { this.destructionTimer = new Timer(selfdestructAfterArg); this.destructionTimer.start(); - // set up self destruction by removing this from the parent messageCache this.destructionTimer.completed.then(async () => { this.universeCache.messageMap.remove(this); + }).catch(err => { + console.log(err); + console.log(this); }); } else { - this.fallBackDestruction(); + plugins.smartdelay.delayFor(1000).then(() => { + if (!this.destructionTimer) { + this.setDestructionTimer(6000); + } + }); } } @@ -93,15 +99,4 @@ export class UniverseMessage implements interfaces.IUniverseMessage { public handleAsBadMessage() { plugins.smartlog.defaultLogger.log('warn', 'received a bad message'); } - - /** - * prevents memory leaks if channels have no default - */ - private fallBackDestruction() { - plugins.smartdelay.delayFor(1000).then(() => { - if (!this.destructionTimer) { - this.setDestructionTimer(6000); - } - }); - } }