-
Notifications
You must be signed in to change notification settings - Fork 355
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
Allow engine to always use native timeout functions #672
Conversation
@vartan thanks for the pull request! Unfortunately, the build has failed: https://github.com/socketio/engine.io-client/runs/3053513196
Could you please check? |
Thanks! I'm not sure how to run those zuul tests, but i think this patch I added binding the functions to window/global should fix that issue. |
…l since transport.socket is not always available.
It seems that zuul issue i was running into previously was transient, I'm able to run the zuul tests now. I fixed the ReferenceError. I also had to install timer functions on transports since they don't always have a reference to this.socket. Let me know if you have any questions or concerns and I'll fix them ASAP! |
Friendly ping? |
@vartan sorry for the delay! The CI still does not pass unfortunately: https://github.com/socketio/engine.io-client/runs/3180153479 |
Sorry, I thought I verified the zuul tests were passing when i sent that out. 57/57 tests are passing on zuul, i tested on Mac (chrome, safari) and ios (mobile safari). |
This allows to control the behavior of mocked timers (@sinonjs/fake-timers), depending on the value of the "useNativeTimers" option: - true: use native setTimeout function - false (default): use classic timers, that may be mocked The "installTimerFunctions" method will also be used in the `socket.io-client` package: ``` import { installTimerFunctions } from "engine.io-client/lib/util"; ``` Note: we could also have put the method in its own library, but that sounded a bit overkill Related: socketio/socket.io-client#1479
This allows to control the behavior of mocked timers (@sinonjs/fake-timers), depending on the value of the "useNativeTimers" option: - true: use native setTimeout function - false (default): use classic timers, that may be mocked The "installTimerFunctions" method will also be used in the `socket.io-client` package: ``` import { installTimerFunctions } from "engine.io-client/lib/util"; ``` Note: we could also have put the method in its own library, but that sounded a bit overkill Related: socketio/socket.io-client#1479
Merged as 5d1d5be. Thanks a lot for your work on this 👍 |
This allows engine.io-client to be used in testing infrastructure (such as Karma) where the clock may be mocked.
Note: the
engine.io.js
file is the generated output ofmake engine.io.js
, and should not be manually modified.The kind of change this PR does introduce
Current behaviour
If the test infrastructure socket attempts to reconnect while a mock clock is installed, it will never reconnect. This happens when Karma is configured to use socket.io.
New behaviour
If the socket attempts to reconnect while the mock clock is installed and
useNativeSetTimeout
is set, then it will not use the mocked clock and will reconnect normallyOther information (e.g. related issues)
following this change, socket.io-client can be updated to call
this.engine.setTimeoutFn
/this.engine.clearTimeoutFn
in place of the native functions so that timeout function selection is only performed once.