- 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
This commit is contained in:
Martin Karkowski 2022-04-08 09:33:31 +02:00
parent 4791914998
commit f4d0460ec2
5 changed files with 98 additions and 10 deletions

View File

@ -54,3 +54,15 @@ Inital commit, which is working with the browser
- dispatcher.getDispatcher: changed option "constructorClass" to "dispatcherConstructorClass"
- helpers.limit.spec: Adapted Timings
- 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

View File

@ -1 +1 @@
1.0.33
1.0.34

View File

@ -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);
});
});
});

View File

@ -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()
}
});

View File

@ -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.
*