Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[webpubsubclient] Fix a bug that 0 sequenceId won't be sent to service #29474

Merged
merged 3 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions sdk/web-pubsub/web-pubsub-client/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Release History

## 1.0.2 (2024-05-01)

### Bugs Fixed

- Fix the bug that `sequenceAck` ping won't be sent if nothing has been received for a client

## 1.0.1 (2024-04-24)

### Other Changes
Expand Down
2 changes: 1 addition & 1 deletion sdk/web-pubsub/web-pubsub-client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@azure/web-pubsub-client",
"version": "1.0.1",
"version": "1.0.2",
"description": "Azure Web PubSub Client",
"sdk-type": "client",
"main": "dist/index.js",
Expand Down
3 changes: 2 additions & 1 deletion sdk/web-pubsub/web-pubsub-client/src/webPubSubClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,8 @@ export class WebPubSubClient {
return;
}
const [isUpdated, seqId] = this._sequenceId.tryGetSequenceId();
if (isUpdated && seqId) {
if (isUpdated && seqId !== null && seqId !== undefined) {
// seqId can be 0
const message: SequenceAckMessage = {
kind: "sequenceAck",
sequenceId: seqId!,
Expand Down
22 changes: 22 additions & 0 deletions sdk/web-pubsub/web-pubsub-client/test/client.lifetime.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,28 @@ describe("WebPubSubClient", function () {
mock.verify();
client.stop();
});

it("SequenceAck as ping", async () => {
const client = new WebPubSubClient("wss://service.com");
const testWs = new TestWebSocketClient(client);
makeStartable(testWs);

const writeMessageSpy = sinon.spy(client["_protocol"], "writeMessage");
await client.start();

// simulate a update
client["_sequenceId"].tryUpdate(0);

// simulate a call
client["_trySendSequenceAck"]();

// expect quick sequenceAck message
sinon.assert.calledWith(
writeMessageSpy,
sinon.match.has("kind", "sequenceAck").and(sinon.match.has("sequenceId", 0)),
);
client.stop();
});
});

function makeStartable(ws: TestWebSocketClient): sinon.SinonStub<[fn: () => void], void> {
Expand Down