Skip to content

Commit 3c82393

Browse files
fix: test and add info log
1 parent 5c3c165 commit 3c82393

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed

packages/sdk/src/protocols/sender/lightpush/index.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,14 @@ class LightPushSDK extends BaseProtocolSDK implements ILightPushSDK {
103103
connectedPeer.id.equals(failure.peerId)
104104
);
105105
if (peer) {
106-
void this.reliabilityMonitor.attemptRetries(failure.peerId, () =>
107-
this.protocol.send(encoder, message, peer)
106+
log.info(`
107+
Failed to send message to peer ${failure.peerId}.
108+
Retrying the message with the same peer in the background.
109+
If this fails, the peer will be renewed.
110+
`);
111+
void this.reliabilityMonitor.attemptRetriesOrRenew(
112+
failure.peerId,
113+
() => this.protocol.send(encoder, message, peer)
108114
);
109115
}
110116
}

packages/sdk/src/protocols/sender/reliability_monitor.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export class SenderReliabilityMonitor {
1313

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

16-
public async attemptRetries(
16+
public async attemptRetriesOrRenew(
1717
peerId: PeerId,
1818
protocolSend: () => Promise<CoreProtocolResult>
1919
): Promise<void> {
@@ -31,13 +31,13 @@ export class SenderReliabilityMonitor {
3131
log.error(
3232
`Failed to send message after retry to ${peerIdStr}: ${result.failure}`
3333
);
34-
await this.attemptRetries(peerId, protocolSend);
34+
await this.attemptRetriesOrRenew(peerId, protocolSend);
3535
}
3636
} catch (error) {
3737
log.error(
3838
`Failed to send message after retry to ${peerIdStr}: ${error}`
3939
);
40-
await this.attemptRetries(peerId, protocolSend);
40+
await this.attemptRetriesOrRenew(peerId, protocolSend);
4141
}
4242
} else {
4343
try {

packages/tests/tests/light-push/peer_management.spec.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { LightNode } from "@waku/interfaces";
22
import { createEncoder, utf8ToBytes } from "@waku/sdk";
3+
import { delay } from "@waku/utils";
34
import { expect } from "chai";
45
import { describe } from "mocha";
56

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

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

90+
await delay(500);
91+
8692
expect(response3.successes.length).to.be.equal(
87-
waku.lightPush.numPeersToUse
93+
waku.lightPush.numPeersToUse - 1
8894
);
95+
expect(response3.failures).to.have.length(1);
8996

9097
expect(response3.successes).to.not.include(peerToDisconnect);
91-
if (response3.failures) {
92-
expect(response3.failures.length).to.equal(0);
93-
}
9498
});
9599
});

0 commit comments

Comments
 (0)