-
Notifications
You must be signed in to change notification settings - Fork 2
feat: trigger reconnect on emit if not connected #162
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
Changes from 4 commits
25cf82c
3dfae09
44553cb
6327b50
992d395
edc804e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -411,18 +411,18 @@ describe("Tests using SimpleSocketIOClient", () => { | |
); | ||
}); | ||
describe("Reconnection tests", () => { | ||
test("attemptReconnect method initialises websocket again", () => { | ||
test("attemptReconnect method initialises websocket again", async () => { | ||
client.initializeWebSocket = vi.fn(); | ||
|
||
client.attemptReconnect(); | ||
await client.attemptReconnect(); | ||
|
||
expect(client.initializeWebSocket).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
test("attemptReconnect method increments attempts count", () => { | ||
test("attemptReconnect method increments attempts count", async () => { | ||
const initialAttempts = client.reconnectionAttempts; | ||
|
||
client.attemptReconnect(); | ||
await client.attemptReconnect(); | ||
|
||
expect(client.reconnectionAttempts).toBe(initialAttempts + 1); | ||
}); | ||
|
@@ -456,7 +456,7 @@ describe("Tests using SimpleSocketIOClient", () => { | |
// Reconnect should not be called yet | ||
expect(client.attemptReconnect).toHaveBeenCalledTimes(0); | ||
}); | ||
test("reconnect method exponentially increase delay for every attempt, stopping at the max value", () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i think it would be helpful with a test that ensures that multiple calls to reconnect during the connection phase does not lead to multiple reconnection attempts in case of failure, just one. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. already implemented ⭐ |
||
test("reconnect method exponentially increase delay for every attempt, stopping at the max value", async () => { | ||
const originalRandom = Math.random; | ||
Math.random = vi.fn().mockReturnValue(1); | ||
vi.useFakeTimers(); | ||
|
@@ -468,6 +468,7 @@ describe("Tests using SimpleSocketIOClient", () => { | |
const expectedMaxDelay = expectedMinDelay * 1.5; | ||
client.reconnecting = false; // Since it never gets to the actual fail state triggered by | ||
client.reconnect(); | ||
await client.initializingPromise; | ||
vi.advanceTimersByTime(expectedMaxDelay + 1); | ||
expect(client.attemptReconnect).toHaveBeenCalledTimes(i + 1); | ||
} | ||
|
Uh oh!
There was an error while loading. Please reload this page.