Skip to content

Commit

Permalink
fix: update UUID only if it changed (#570)
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinKolarik authored Nov 12, 2024
1 parent 7cbeed2 commit 89ef791
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
10 changes: 5 additions & 5 deletions src/lib/override/adopted-probes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ export class AdoptedProbes {
}

if (connectedProbeByIp) { // probe was found by ip, but data is outdated
return this.updateIds(ip, connectedProbeByIp);
return this.updateIds(ip, uuid, connectedProbeByIp);
}

let connectedProbeByAltIp: Probe | undefined;
Expand All @@ -261,7 +261,7 @@ export class AdoptedProbes {

if (connectedProbeByAltIp) { // probe was found by alt ip, need to update the adopted data
logger.info('Found by alt IP.', { old: { ip, uuid }, new: { ip: connectedProbeByAltIp.ipAddress, altIps: connectedProbeByAltIp.altIpAddresses, uuid: connectedProbeByAltIp.uuid } });
await this.updateIds(ip, connectedProbeByAltIp);
await this.updateIds(ip, uuid, connectedProbeByAltIp);
}

if (!uuid) { // uuid is null, so no searching by uuid is required
Expand All @@ -272,7 +272,7 @@ export class AdoptedProbes {

if (connectedProbeByUuid) { // probe was found by uuid, need to update the adopted data
logger.info('Found by UUID.', { old: { ip, uuid }, new: { ip: connectedProbeByUuid.ipAddress, altIps: connectedProbeByUuid.altIpAddresses, uuid: connectedProbeByUuid.uuid } });
await this.updateIds(ip, connectedProbeByUuid);
await this.updateIds(ip, uuid, connectedProbeByUuid);
}
}

Expand Down Expand Up @@ -338,11 +338,11 @@ export class AdoptedProbes {
}
}

private async updateIds (currentAdoptedIp: string, connectedProbe: Probe) {
private async updateIds (currentAdoptedIp: string, uuid: string | null, connectedProbe: Probe) {
await this.sql(ADOPTED_PROBES_TABLE).where({ ip: currentAdoptedIp }).update({
ip: connectedProbe.ipAddress,
altIps: JSON.stringify(connectedProbe.altIpAddresses),
uuid: connectedProbe.uuid,
...connectedProbe.uuid !== uuid ? { uuid: connectedProbe.uuid } : {},
});

const adoptedProbe = this.getByIp(currentAdoptedIp);
Expand Down
4 changes: 2 additions & 2 deletions test/tests/unit/override/adopted-probes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ describe('AdoptedProbes', () => {
expect(whereStub.callCount).to.equal(1);
expect(whereStub.args[0]).to.deep.equal([{ ip: '1.1.1.1' }]);
expect(updateStub.callCount).to.equal(1);
expect(updateStub.args[0]).to.deep.equal([{ ip: '2.2.2.2', altIps: '[]', uuid: '1-1-1-1-1' }]);
expect(updateStub.args[0]).to.deep.equal([{ ip: '2.2.2.2', altIps: '[]' }]);
});

it('class should update alt ips if it is wrong', async () => {
Expand All @@ -146,7 +146,7 @@ describe('AdoptedProbes', () => {
expect(whereStub.callCount).to.equal(1);
expect(whereStub.args[0]).to.deep.equal([{ ip: '1.1.1.1' }]);
expect(updateStub.callCount).to.equal(1);
expect(updateStub.args[0]).to.deep.equal([{ ip: '1.1.1.1', altIps: JSON.stringify([ '2.2.2.2' ]), uuid: '1-1-1-1-1' }]);
expect(updateStub.args[0]).to.deep.equal([{ ip: '1.1.1.1', altIps: JSON.stringify([ '2.2.2.2' ]) }]);
});

it('class should update status to "offline" if adopted probe was not found', async () => {
Expand Down

0 comments on commit 89ef791

Please sign in to comment.