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

Allow engine to always use native timeout functions #672

Closed
wants to merge 8 commits into from

Conversation

vartan
Copy link
Contributor

@vartan vartan commented Jul 7, 2021

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 of make engine.io.js, and should not be manually modified.

The kind of change this PR does introduce

  • a bug fix
  • a new feature
  • an update to the documentation
  • a code change that improves performance
  • other

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 normally

Other 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.

@darrachequesne
Copy link
Member

@vartan thanks for the pull request! Unfortunately, the build has failed: https://github.com/socketio/engine.io-client/runs/3053513196

Error: 'setTimeout' called on an object that does not implement interface Window.

Could you please check?

@vartan
Copy link
Contributor Author

vartan commented Jul 13, 2021

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.
@vartan
Copy link
Contributor Author

vartan commented Jul 20, 2021

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!

@vartan
Copy link
Contributor Author

vartan commented Jul 27, 2021

Friendly ping?

@darrachequesne
Copy link
Member

@vartan sorry for the delay! The CI still does not pass unfortunately: https://github.com/socketio/engine.io-client/runs/3180153479

@vartan
Copy link
Contributor Author

vartan commented Jul 28, 2021

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).

darrachequesne pushed a commit that referenced this pull request Jul 30, 2021
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
darrachequesne pushed a commit that referenced this pull request Jul 30, 2021
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
@darrachequesne
Copy link
Member

Merged as 5d1d5be. Thanks a lot for your work on this 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants