Skip to content

Commit

Permalink
fix: test and add info log
Browse files Browse the repository at this point in the history
  • Loading branch information
danisharora099 committed Sep 12, 2024
1 parent b12230c commit e51e369
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
10 changes: 8 additions & 2 deletions packages/sdk/src/protocols/sender/lightpush/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,14 @@ class LightPushSDK extends BaseProtocolSDK implements ILightPushSDK {
connectedPeer.id.equals(failure.peerId)
);
if (peer) {
void this.reliabilityMonitor.attemptRetries(failure.peerId, () =>
this.protocol.send(encoder, message, peer)
log.info(`
Failed to send message to peer ${failure.peerId}.
Retrying the message with the same peer in the background.
If this fails, the peer will be renewed.
`);
void this.reliabilityMonitor.attemptRetriesOrRenew(
failure.peerId,
() => this.protocol.send(encoder, message, peer)
);
}
}
Expand Down
6 changes: 3 additions & 3 deletions packages/sdk/src/protocols/sender/reliability_monitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class SenderReliabilityMonitor {

public constructor(private renewPeer: (peerId: PeerId) => Promise<Peer>) {}

public async attemptRetries(
public async attemptRetriesOrRenew(
peerId: PeerId,
protocolSend: () => Promise<CoreProtocolResult>
): Promise<void> {
Expand All @@ -31,13 +31,13 @@ export class SenderReliabilityMonitor {
log.error(
`Failed to send message after retry to ${peerIdStr}: ${result.failure}`
);
await this.attemptRetries(peerId, protocolSend);
await this.attemptRetriesOrRenew(peerId, protocolSend);
}
} catch (error) {
log.error(
`Failed to send message after retry to ${peerIdStr}: ${error}`
);
await this.attemptRetries(peerId, protocolSend);
await this.attemptRetriesOrRenew(peerId, protocolSend);
}
} else {
try {
Expand Down
14 changes: 9 additions & 5 deletions packages/tests/tests/light-push/peer_management.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { LightNode } from "@waku/interfaces";
import { createEncoder, utf8ToBytes } from "@waku/sdk";
import { delay } from "@waku/utils";
import { expect } from "chai";
import { describe } from "mocha";

Expand Down Expand Up @@ -78,18 +79,21 @@ describe("Waku Light Push: Peer Management: E2E", function () {
expect(response2.failures).to.have.length(1);
expect(response2.failures?.[0].peerId).to.equal(peerToDisconnect);

// send another lightpush request -- renewal should have triggerred and new peer should be used instead of the disconnected one
// send another lightpush request
// reattempts to send should be triggerred
// then renewal should happen
// so one failure should exist
const response3 = await waku.lightPush.send(encoder, {
payload: utf8ToBytes("Hello_World")
});

await delay(500);

expect(response3.successes.length).to.be.equal(
waku.lightPush.numPeersToUse
waku.lightPush.numPeersToUse - 1
);
expect(response3.failures).to.have.length(1);

expect(response3.successes).to.not.include(peerToDisconnect);
if (response3.failures) {
expect(response3.failures.length).to.equal(0);
}
});
});

0 comments on commit e51e369

Please sign in to comment.