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

Assign emulator ports and resolve hostnames upfront. #5083

Merged
merged 6 commits into from
Oct 7, 2022
Merged

Conversation

yuchenshi
Copy link
Member

Description

This PR explicitly resolves hostnames like localhost to IP addresses like 127.0.0.1, ::1 before listening for each emulator and assigns all the ports all at once early in the process.

It also modifies the Emulator Hub to listen on as many addresses as it can to increase the chance of successful discovery (no matter the client is v4- or v6-only). If we like what we're seeing here, we can apply this to most other Node.js-based emulators (see comments inline).

The new test process use the more reliable net Socket instead of tcp-port-used. There's only one instance of it left to test for port closed (occupied by emulator), and I wonder if we still need it. (Also, the new test process is more or less similar to portfinder and maybe we can remove the dependency of it one day, after we update all the other usages.)

Since the ports are all allocated early, this may fix the frameworks autoinit integration.

Scenarios Tested

Manually started the emulators, observed what ports are allocated with --debug, including when ports are partially occupied. ProTip: You can occupy a specific address with python3 -m http.server --bind ::1 9999 IPv4 (or 127.0.0.1 for IPv4). I've tested that when the preferred IPv4 address is occupied, the process gives an error. A warning is given when secondary addresses are occupied.

Sample Commands

// Listening on multiple addresses to maximize the chance of discovery.
hub: false,

// TODO: Modify the following emulators to listen on multiple addresses.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q: Do want this to happen in the same release or later?

@codecov-commenter
Copy link

codecov-commenter commented Oct 7, 2022

Codecov Report

Base: 55.97% // Head: 56.04% // Increases project coverage by +0.06% 🎉

Coverage data is based on head (3317f3d) compared to base (a7a3e62).
Patch coverage: 42.71% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5083      +/-   ##
==========================================
+ Coverage   55.97%   56.04%   +0.06%     
==========================================
  Files         306      307       +1     
  Lines       20484    20629     +145     
  Branches     4135     4164      +29     
==========================================
+ Hits        11466    11561      +95     
- Misses       8036     8068      +32     
- Partials      982     1000      +18     
Impacted Files Coverage Δ
src/emulator/hubClient.ts 14.28% <0.00%> (-6.77%) ⬇️
src/emulator/types.ts 45.55% <ø> (ø)
src/emulator/controller.ts 13.22% <1.36%> (+0.45%) ⬆️
src/emulator/hub.ts 16.49% <15.00%> (-2.14%) ⬇️
src/emulator/emulatorLogger.ts 31.49% <37.50%> (+0.34%) ⬆️
src/frameworks/index.ts 16.45% <50.00%> (ø)
src/emulator/portUtils.ts 52.10% <52.38%> (-13.62%) ⬇️
src/emulator/ExpressBasedEmulator.ts 75.00% <75.00%> (ø)
src/emulator/dns.ts 100.00% <100.00%> (ø)
... and 2 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

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.

4 participants