-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Syntax: ```js const socket = io({ retries: 3, ackTimeout: 10000 }); // "my-event" will be sent up to 4 times (1 + 3), until the server sends an acknowledgement socket.emit("my-event", (err) => {}); ``` Notes: - the order of the packets is guaranteed, as we send packets one by one - the same packet id is reused for consecutive retries, in order to allow deduplication on the server side
- Loading branch information
1 parent
9f32925
commit 655dce9
Showing
4 changed files
with
187 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import expect from "expect.js"; | ||
import { io } from ".."; | ||
import { wrap, BASE_URL, success } from "./support/util"; | ||
|
||
describe("retry", () => { | ||
it("should preserve the order of the packets", () => { | ||
return wrap((done) => { | ||
const socket = io(BASE_URL, { | ||
forceNew: true, | ||
retries: 1, | ||
ackTimeout: 50, | ||
}); | ||
|
||
socket.emit("echo", 1, () => { | ||
// @ts-ignore | ||
expect(socket._queue.length).to.eql(2); | ||
}); | ||
|
||
// @ts-ignore | ||
expect(socket._queue.length).to.eql(1); | ||
|
||
socket.emit("echo", 2, () => { | ||
// @ts-ignore | ||
expect(socket._queue.length).to.eql(1); | ||
}); | ||
|
||
// @ts-ignore | ||
expect(socket._queue.length).to.eql(2); | ||
|
||
socket.emit("echo", 3, (err, val) => { | ||
expect(err).to.be(null); | ||
expect(val).to.eql(3); | ||
// @ts-ignore | ||
expect(socket._queue.length).to.eql(0); | ||
|
||
success(done, socket); | ||
}); | ||
|
||
// @ts-ignore | ||
expect(socket._queue.length).to.eql(3); | ||
}); | ||
}); | ||
|
||
it("should fail when the server does not acknowledge the packet", () => { | ||
return wrap((done) => { | ||
const socket = io(BASE_URL, { | ||
forceNew: true, | ||
retries: 3, | ||
ackTimeout: 50, | ||
}); | ||
|
||
let count = 0; | ||
|
||
socket.emit("ack", () => { | ||
expect(count).to.eql(4); | ||
|
||
success(done, socket); | ||
}); | ||
|
||
socket.on("ack", () => { | ||
count++; | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters