Skip to content

test: Prevent test timeout error by properly closing server #2490

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

Merged
merged 17 commits into from
Mar 12, 2025

Conversation

dplewis
Copy link
Member

@dplewis dplewis commented Mar 9, 2025

Pull Request

Issue

https://github.com/parse-community/Parse-SDK-JS/actions/runs/13735695802/job/38419094737?pr=2486

Error: Timeout - Async function did not complete within 20000ms (set by jasmine.DEFAULT_TIMEOUT_INTERVAL)

parseServer.handleShutdown calls liveQueryServer.server.close(). When initializing the server with startLiveQueryServer option liveQueryServer.server and parseServer.server are the same so we are calling server.close() twice. This maybe the cause of the issue. As we can see the tests still pass without getting an EADDRINUSE error because now we are calling close once.

See: #2487

Approach

  • Remove unused route
  • Cache distribution files for performance
  • Remove multiple server close events.
  • Improve shutdown tests
  • Refactor handleShutdown
  • Set REQUEST_ATTEMPT_LIMIT to 1 to check for network drops
  • Remove afterAll since the tests end at this point we don't care about open connections as the server will shutdown anyway.

If the issue persists then we can try to close all the connections. server.close prevents new connections but keeps existing ones alive until they are closed. There is now a server.closeAllConnections() method introduced in Node v18.2.0. If all else fails we can look into parseServer.handleShutdown() internals.

Copy link

parse-github-assistant bot commented Mar 9, 2025

Thanks for opening this pull request!

  • ❌ Please link an issue that describes the reason for this pull request, otherwise your pull request will be closed. Make sure to write it as Closes: #123 in the PR description, so I can recognize it.

Copy link

codecov bot commented Mar 9, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (43cba58) to head (d93d21a).
Report is 20 commits behind head on alpha.

Additional details and impacted files
@@            Coverage Diff            @@
##             alpha     #2490   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           64        64           
  Lines         6268      6268           
  Branches      1468      1468           
=========================================
  Hits          6268      6268           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@dplewis dplewis requested a review from a team March 9, 2025 02:28
@dplewis
Copy link
Member Author

dplewis commented Mar 9, 2025

@mtrezza The issue still occurred. https://github.com/parse-community/Parse-SDK-JS/actions/runs/13749596429/job/38448859505

This tells me that this issue is with parseServer.handleShutdown() stalling. I added logic to run handleShutdown in the background and listen to the close event. I also destroyed all the connections to ensure the event is emitted. afdeb2b

Destroy connections was removed in #2185. This didn't work because you have to destroy the connections after you call server.close() to prevent a race condition.

https://nodejs.org/api/net.html#event-close

Emitted when the server closes. If connections exist, this event is not emitted until all connections are ended.

If this fails again the offending line is in handleShutdown for the same reasons stated above
https://github.com/parse-community/parse-server/blob/4f55c3e9cfa31c6aca9c005ab21ff6193600ba89/src/ParseServer.js#L232

@dplewis
Copy link
Member Author

dplewis commented Mar 9, 2025

@mtrezza Until parseServer.handleShutdown is fixed on the server I moved the shutdown logic here. This gives us better control of the shutdown process. This should be good to merge. I ran it 20 times locally and got no errors timeout errors.

@dplewis dplewis requested a review from mtrezza March 9, 2025 19:46
@dplewis
Copy link
Member Author

dplewis commented Mar 12, 2025

@mtrezza This is ready for review

@mtrezza
Copy link
Member

mtrezza commented Mar 12, 2025

@mtrezza Until parseServer.handleShutdown is fixed on the server I moved the shutdown logic here. This gives us better control of the shutdown process. This should be good to merge. I ran it 20 times locally and got no errors timeout errors.

Are you referring to parse-community/parse-server#9634? Since it has been merged, are there any changes needed here, e.g. can the shutdown logic be removed here - because you wrote "Until parseServer.handleShutdown is fixed..."?

@dplewis
Copy link
Member Author

dplewis commented Mar 12, 2025

You can merge this now then we can change it whenever parse-community/parse-server#9634 gets merged (I hope it works) and the server update gets released. This should work fine as is.

@mtrezza mtrezza merged commit 478147c into parse-community:alpha Mar 12, 2025
12 checks passed
@dplewis dplewis deleted the improve-test branch March 12, 2025 23:51
@parseplatformorg
Copy link
Contributor

🎉 This change has been released in version 6.1.0-alpha.3

@parseplatformorg parseplatformorg added the state:released-alpha Released as alpha version label Mar 16, 2025
@parseplatformorg
Copy link
Contributor

🎉 This change has been released in version 6.1.0

@parseplatformorg parseplatformorg added the state:released Released as stable version label Mar 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
state:released Released as stable version state:released-alpha Released as alpha version
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants