diff --git a/CHANGELOG.md b/CHANGELOG.md index f35da1a..f26f83e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -53,4 +53,16 @@ Inital commit, which is working with the browser - communication.getLayer.nodejs/browser: adding default value for logger - dispatcher.getDispatcher: changed option "constructorClass" to "dispatcherConstructorClass" - helpers.limit.spec: Adapted Timings - - loader.getPackageLoader.nodejs/browser: Changed the options. \ No newline at end of file + - loader.getPackageLoader.nodejs/browser: Changed the options. + +# 1.0.34 +- Fixes: + - dispatchers.ConnectivityManager.ConnectivityManager: fixing isMaster- Fixed +- Modified: + - types.nope.ConnectivityManager.interface: + - INopeStatusInfo.upTime =renamed=> connectedSince + - INopeConnectivityManager added => "upTime" and "connectedSince" + - dispatchers.ConnectivityManager.ConnectivityManager: + - INopeConnectivityManager added "connectedSince" (which is expressed in the adapted Timestamp.) +- Added: + - dispatchers.ConnectivityManager.ConnectivityManager.spec: Added Master - Test \ No newline at end of file diff --git a/contribute/VERSION b/contribute/VERSION index c1cf2f9..64a736b 100644 --- a/contribute/VERSION +++ b/contribute/VERSION @@ -1 +1 @@ -1.0.33 \ No newline at end of file +1.0.34 \ No newline at end of file diff --git a/lib/dispatcher/ConnectivityManager/ConnectivityManager.spec.ts b/lib/dispatcher/ConnectivityManager/ConnectivityManager.spec.ts index c12243d..0841286 100644 --- a/lib/dispatcher/ConnectivityManager/ConnectivityManager.spec.ts +++ b/lib/dispatcher/ConnectivityManager/ConnectivityManager.spec.ts @@ -6,7 +6,7 @@ * @desc [description] */ -import { expect } from "chai"; +import { assert, expect } from "chai"; import { beforeEach, describe, it } from "mocha"; import "reflect-metadata"; import { getLayer } from "../../communication/getLayer.nodejs"; @@ -85,7 +85,7 @@ describe("NopeConnectivityManager", function () { logger: false, }, () => new NopeObservable(), - "test" + "first" ); first.ready.waitFor().then(() => done()); @@ -197,6 +197,42 @@ describe("NopeConnectivityManager", function () { first.dispose(true); expect(end - adapted).to.be.equal(0, "There should not be an delta."); + + + }); + + it("master", async () => { + // Wait for the Handshake + await sleep(10); + + assert(first.isMaster, "First should be master"); + + // Create the second Element. + const second = new NopeConnectivityManager( + { + communicator, + logger: false, + }, + () => new NopeObservable(), + "second" + ); + + // Wait for the Handshake + await sleep(10); + + assert(first.isMaster, "First should be master"); + assert(second.isMaster == false, "Second should not be master"); + assert( + first.master.id == first.id, + "First should recognize the first as master" + ); + assert( + second.master.id == first.id, + "Second should recognize the first as master" + ); + + first.dispose(true); + second.dispose(true); }); }); }); diff --git a/lib/dispatcher/ConnectivityManager/ConnectivityManager.ts b/lib/dispatcher/ConnectivityManager/ConnectivityManager.ts index f0a4561..4d44221 100644 --- a/lib/dispatcher/ConnectivityManager/ConnectivityManager.ts +++ b/lib/dispatcher/ConnectivityManager/ConnectivityManager.ts @@ -21,7 +21,7 @@ import { INopeINopeConnectivityOptions, INopeINopeConnectivityTimeOptions, INopeObservable, - INopeStatusInfo, + INopeStatusInfo } from "../../types/nope"; // Chached Moduls, which will be loaded in nodejs @@ -146,7 +146,7 @@ export class NopeConnectivityManager implements INopeConnectivityManager { }, pid: process.pid, timestamp: this.now, - upTime: this.upTime, + connectedSince: this.connectedSince, status: ENopeDispatcherStatus.HEALTHY, }; } @@ -172,7 +172,7 @@ export class NopeConnectivityManager implements INopeConnectivityManager { id: this.id, pid: this.id, timestamp: this.now, - upTime: this.upTime, + connectedSince: this.connectedSince, status: ENopeDispatcherStatus.HEALTHY, }; } @@ -245,6 +245,18 @@ export class NopeConnectivityManager implements INopeConnectivityManager { return Date.now() - this._connectedSince; } + /** + * see {@link INopeConnectivityManager.connectedSince} + * + * @author M.Karkowski + * @readonly + * @type {number} + * @memberof NopeConnectivityManager + */ + public get connectedSince(): number { + return this._connectedSince + this._deltaTime; + } + /** * Internal value to store the Master. * @@ -276,9 +288,9 @@ export class NopeConnectivityManager implements INopeConnectivityManager { */ public get isMaster(): boolean { if (this.__isMaster === null) { - const upTime = this.upTime; + const connectedSince = this._connectedSince; for (const info of this.dispatchers.originalData.values()) { - if (info.upTime >= upTime) { + if (info.id !== this.id && info.connectedSince < connectedSince) { return false; } } @@ -363,6 +375,9 @@ export class NopeConnectivityManager implements INopeConnectivityManager { 'Remote Dispatcher "' + dispatcherId + '" went online' ); } + + // Say Hello by sending the Status + _this._sendStatus() } }); diff --git a/lib/types/nope/nopeConnectivityManager.interface.ts b/lib/types/nope/nopeConnectivityManager.interface.ts index abec6e6..041818e 100644 --- a/lib/types/nope/nopeConnectivityManager.interface.ts +++ b/lib/types/nope/nopeConnectivityManager.interface.ts @@ -81,7 +81,7 @@ export interface INopeStatusInfo { * @type {number} * @memberof INopeStatusInfo */ - upTime: number; + connectedSince: number; /** * The Status of the Dispatcher * @@ -255,6 +255,13 @@ export interface INopeConnectivityManager { */ readonly id: string; + /** + * The current info of this connectivity-manager. + * + * @author M.Karkowski + * @type {INopeStatusInfo} + * @memberof INopeConnectivityManager + */ readonly info: INopeStatusInfo; /** @@ -342,6 +349,24 @@ export interface INopeConnectivityManager { */ readonly now: number; + /** + * The time since the systeme is connected. + * + * @author M.Karkowski + * @type {number} + * @memberof INopeConnectivityManager + */ + readonly upTime: number; + + /** + * Timestamp of the connection since it has been established. + * + * @author M.Karkowski + * @type {number} + * @memberof INopeConnectivityManager + */ + readonly connectedSince: number; + /** * Returns the Status of the Master. *