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

feat: try other logger ports #3534

Open
wants to merge 24 commits into
base: main
Choose a base branch
from

Conversation

DevanceJ
Copy link
Contributor

@DevanceJ DevanceJ commented Mar 14, 2024

  • I have read the contribution documentation for this project.
  • I agree to follow the code of conduct that this project follows, as appropriate.
  • The changes are appropriately documented (if applicable).
  • The changes have sufficient test coverage (if applicable).
  • The testsuite passes successfully on my local machine (if applicable).

Summarize your changes:
Fixes #3204

  1. Checks for availability of ports from 9000-9010.
  2. Shows which port has been assigned.
  3. Throws an appropriate error message for better user experience.

@DevanceJ DevanceJ requested a review from a team as a code owner March 14, 2024 13:12
@DevanceJ DevanceJ changed the title feat/try other logger ports feat: try other logger ports Mar 14, 2024
@DevanceJ
Copy link
Contributor Author

Currently I am only checking till port 9009, @erickzhao can you guide me if we should increase the upper limit for this port availability checking.

Copy link
Member

@BlackHole1 BlackHole1 left a comment

Choose a reason for hiding this comment

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

findAvailablePort should be split into two functions for easier unit testing and logical decoupling.
I think it would be better if you can move the port-related functions to a different location, as I remember similar requirements elsewhere in the forge.

Moreover, in my opinion, the Logger doesn't actually need to include port-related code, it would be better if it were passed from the outside. For example: logger.start(port).

It would be great if you could add relevant unit tests. Thank you for your contribution!

packages/utils/web-multi-logger/src/Logger.ts Outdated Show resolved Hide resolved
packages/utils/web-multi-logger/src/Logger.ts Outdated Show resolved Hide resolved
@DevanceJ
Copy link
Contributor Author

Hi @BlackHole1, just made the changes that you suggested in code review and wrote unit tests for Logger.ts. I couldn't directly test the private functions such as portOccupied and findAvailablePort, so I wrote test for start() such that the private functions are tested without changing Access levels.

Thank you for the code review, I hope this fixes the issue. Glad to Contribute.

@BlackHole1
Copy link
Member

Can you move portOccupied and findAvailablePort to packages/utils/core-utils/src?

  1. Create a file port.ts in the packages/utils/core-utils/src directory.
  2. Move portOccupied and findAvailablePort to port.ts as arrow functions (not as class members).
  3. Add a file port_spec.ts in the packages/utils/core-utils/test directory and write unit tests.

packages/utils/core-utils/src/port.ts Outdated Show resolved Hide resolved
packages/utils/core-utils/test/port_spec.ts Show resolved Hide resolved
@DevanceJ
Copy link
Contributor Author

Note:
Currently one of the tests that I have written are dependent on port 49152 i.e if that port is occupied one my test will fail. We can get rid of this dependency by removing the tests that use 49152 because the tests that check for rejection are indirectly checking for these test.

I am new to writing tests so I might be wrong

packages/utils/core-utils/test/port_spec.ts Outdated Show resolved Hide resolved
packages/utils/core-utils/src/port.ts Outdated Show resolved Hide resolved
packages/utils/core-utils/src/port.ts Outdated Show resolved Hide resolved
packages/plugin/webpack/src/WebpackPlugin.ts Outdated Show resolved Hide resolved
Copy link
Member

@BlackHole1 BlackHole1 left a comment

Choose a reason for hiding this comment

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

LGTM. Thank you for contribute.

PTAL @dsanders11 @erickzhao

@BlackHole1
Copy link
Member

When I updated the current branch, the CI failed, it seems to be related to Code Lint. @DevanceJ, can you try to fix it?

@DevanceJ
Copy link
Contributor Author

Hi Kevin, I just saw this. Working on it now!

@DevanceJ
Copy link
Contributor Author

Looking at the time the tests take, can you check my pr adding parallelism in circleci/config #3536.😁

@BlackHole1
Copy link
Member

Looking at the time the tests take, can you check my pr adding parallelism in circleci/config #3536.😁

I am not very familiar with CircleCI, so #3536 may need to be reviewed by @dsanders11 and @georgexu99.

@BlackHole1 BlackHole1 requested a review from a team March 26, 2024 01:21
@DevanceJ
Copy link
Contributor Author

Hey, I have fixed the CI errors in the previous merge from main.

@DevanceJ
Copy link
Contributor Author

Hi Erick,
I have Refactored portOccupied function for clarity and reliability. Updated test cases accordingly.

@DevanceJ DevanceJ requested a review from erickzhao April 20, 2024 02:58
@erickzhao erickzhao dismissed BlackHole1’s stale review May 6, 2024 16:18

BlackHole1 left a LGTM comment above

@DevanceJ
Copy link
Contributor Author

DevanceJ commented May 9, 2024

Looking into this error.

@DevanceJ
Copy link
Contributor Author

Hi I am getting this error

TSError: ⨯ Unable to compile TypeScript: packages/plugin/webpack/src/WebpackPlugin.ts:574:42 - error TS2554: Expected 0 arguments, but got 1. 574 this.loggerPort = await logger.start(this.loggerPort as number);

when I run yarn test locally but the start method does expect a parameter in reality. Any help on this is appreciated.

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.

Try other ports when port 9000 is already used
3 participants