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

Enable test suite to be randomized #7265

Merged
merged 30 commits into from
Mar 15, 2021
Merged

Enable test suite to be randomized #7265

merged 30 commits into from
Mar 15, 2021

Conversation

dplewis
Copy link
Member

@dplewis dplewis commented Mar 13, 2021

New Pull Request Checklist

Issue Description

Per a discussion #7262 (comment)
This is an attempt to run the tests at random. By random means each test file will be ran at random. While a test file is running the test within the file will be randomized. A test may rely on a previously run test and would be deemed poorly written.

Related issue: FILL_THIS_OUT

Approach

Majority of the tests have already been fixed in #7262. This is a first pass attempt. This could be a community effort. If it seems too daunting of a task we can still merge but remove random.

Known Failing Test Suites

  • CLI.spec.js
    No error here just wanted to set the server to different ports. Easier for debugging
  • FileController.spec.js
    The mock adapter was changed and never reset
  • GridFSBucketStorageAdapter.spec.js
    Config not properly set
  • index.spec.js
    Properly close servers and reset
  • LdapAuth.spec.js
    Bug I rewrote the test getting rid of Promise.finally. I then noticed the servers couldn't close on group search error. If there was an error I unbind and destroyed the client similar to how other errors are handled.
  • LoggerController.spec.js
    Assumed a log would exist.
  • ParseGeoPoint.spec.js
    Bug Ensure multiple geopoint field validation runs before any operation.
  • ParseGraphQLServer.spec.js
    Initialized new server beforeEach test and close after. Set unique field names in tests.
  • ParseHooks.spec.js
    Remove the use of AppCache. Changed server port to not conflict with LdapAuth.spec.js
  • ParseLiveQueryServer.spec.js
    Properly close servers and reset
  • PostgresInitOptions.spec.js
    Changed server port to not conflict with index.spec.js
  • PushController.spec.js
    Ensure pushStatus object exists.
  • UserController.spec.js
    Resets the mockEmailAdapter. Remove the use of AppCache. This cause the Config to be improperly set. Normally it would run at the end of the test run alphabetically. In a random test it ran first. Thats how I was able to find this issue.
    See: https://github.com/parse-community/parse-server/runs/2103910826 The tests immediately started failing. I don't know why when the cache gets cleared on every reconfigureServer.
  • RedisCacheAdapter.spec.js
    Clear cache before every test
  • UserPII.spec.js
    The issue was the protectedFields gets merged with defaults. Once merged every subsequent reconfigureServer call would use the previous protectedFields from defaults. Caused by https://github.com/parse-community/parse-server/blob/random-tests/src/ParseServer.js#L419
  • batch.spec.js / ParseRESTController.spec.js (transactions)
    These tests timeout I believe this could be a server issue
  • PushController.spec.js / Parse.Push.spec.js
    These tests timeout I believe this could be a server issue

Critical

  • Error: Unable to connect to Parse API
    The most likely cause of this that the JS SDK is a singleton and will get reinitialized when you create a new Server instance. It also gets initialized with the serverURL you set. In our case the servers closed but the serverURL was the same. Meaning all test will use the old serverURL until a new Server instance is created.
  • Error: listen EADDRINUSE: address already in use 0.0.0.0:8378
    Caused when a test timeout the file descriptor is open keeping the server from closing. Similar to the client being alive prevents closing the server in LdapAuth.spec.js. I added destroyAliveConnections to mitigate this risk.
    It was caused by error: tuple concurrently updated

Nice to have

  • Move non spec files to /support

TODOs before merging

  • Add test cases
  • Add entry to changelog
  • Add changes to documentation (guides, repository pages, in-code descriptions)
  • Add security check
  • Add new Parse Error codes to Parse JS SDK
  • ...

@codecov
Copy link

codecov bot commented Mar 13, 2021

Codecov Report

Merging #7265 (326a0f4) into master (9563793) will decrease coverage by 0.02%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #7265      +/-   ##
==========================================
- Coverage   94.01%   93.98%   -0.03%     
==========================================
  Files         179      179              
  Lines       13140    13144       +4     
==========================================
  Hits        12354    12354              
- Misses        786      790       +4     
Impacted Files Coverage Δ
src/Adapters/Auth/ldap.js 94.23% <100.00%> (+0.23%) ⬆️
src/Adapters/Cache/RedisCacheAdapter/index.js 94.73% <100.00%> (+0.09%) ⬆️
src/Controllers/SchemaController.js 97.33% <100.00%> (+<0.01%) ⬆️
src/ParseServerRESTController.js 97.01% <0.00%> (-1.50%) ⬇️
src/Adapters/Files/GridFSBucketAdapter.js 79.50% <0.00%> (-0.82%) ⬇️
src/RestWrite.js 93.84% <0.00%> (-0.17%) ⬇️
...dapters/Storage/Postgres/PostgresStorageAdapter.js 95.50% <0.00%> (-0.08%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9563793...326a0f4. Read the comment docs.

@dplewis dplewis changed the title Enable test suite to be randomized [WIP] Enable test suite to be randomized Mar 13, 2021
@dplewis
Copy link
Member Author

dplewis commented Mar 13, 2021

@parse-community/core-maintainers I need some help with an issue.

I realized that sometimes config.fileController or config.database (databaseController) is undefined. Is there any situation when you start a server the config would be empty or any other way it could be set to empty? I can't remember and will look around, just wanted to ask.

I believe this is the last piece to the puzzle.

Edit: https://github.com/parse-community/parse-server/blob/master/src/Config.js#L31

@mtrezza
Copy link
Member

mtrezza commented Mar 13, 2021

Is there any situation when you start a server the config would be empty or any other way it could be set to empty?

I remember someone mentioning this in an issue some weeks ago, I think @davimacedo made a comment on it, not sure. In the context of jasmine, I can think of

  • a test starting before the server is fully initialized, maybe when calling reconfigureServer without await?
  • an issue in the helper.js or reconfigureSever itself?

Maybe the reconfigureSever also does not fully reconfigure everything, or the config object that the helper is using is directly modified by a test, so the modification is persistent. Maybe Object.freeze helps.

@dplewis
Copy link
Member Author

dplewis commented Mar 14, 2021

Is there any situation when you start a server the config would be empty or any other way it could be set to empty?

@mtrezza I figured out the issue, it was caused by UserController.spec.js. I updated my finding in the OP.

@dplewis
Copy link
Member Author

dplewis commented Mar 14, 2021

@davimacedo @mtrezza This is good for review. Let me know if you have any questions.

I don’t know how many flaky tests still exist. My final conclusion is 2800+ test and not one server change, that says something.

@mtrezza
Copy link
Member

mtrezza commented Mar 14, 2021

My final conclusion is 2800+ test and not one server change, that says something.

Can you explain what that means?

@dplewis
Copy link
Member Author

dplewis commented Mar 14, 2021

After spending dozens of hours cleaning up hundreds of poorly written test. I didn’t find a single server bug. At least I have enough knowledge about the test suite to fix the flaky tests next

@mtrezza
Copy link
Member

mtrezza commented Mar 14, 2021

Pretty cool! Do you have any general recommendations as to how the test suites are set up or is that principally fine as it is?

@dplewis
Copy link
Member Author

dplewis commented Mar 14, 2021

Do you have any general recommendations as to how the test suites are set up or is that principally fine as it is?

I think it's fine the way it is. Its actually pretty simple when you compare it to the JS SDK.

I didn’t find a single server bug.

@mtrezza I found one lol in the LdapAuth.spec.js

@dplewis dplewis requested a review from davimacedo March 14, 2021 22:26
Copy link
Member

@davimacedo davimacedo left a comment

Choose a reason for hiding this comment

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

Great job, @dplewis ! It looks all good to me.

@dplewis dplewis merged commit 1666c3e into master Mar 15, 2021
@dplewis dplewis deleted the random-tests branch March 15, 2021 07:04
@dplewis dplewis mentioned this pull request Mar 15, 2021
4 tasks
Arul- added a commit to Arul-/parse-server that referenced this pull request Mar 25, 2021
* initial run

* Update ParseGraphQLServer.spec.js

* temporarily enable reporter

* Bump retry limit

* fix undefined database

* try to catch error

* Handle LiveQueryServers

* Update Config.js

* fast-fail false

* Remove usage of AppCache

* oops

* Update contributing guide

* enable debugger, try network retry attempt 1

* Fix ldap unbinding

* move non specs to support

* add missing mock adapter

* fix Parse.Push

* RestController should match batch.spec.js

* Remove request attempt limit

* handle index.spec.js

* Update CHANGELOG.md

* Handle error: tuple concurrently updated

* test transactions

* Clear RedisCache after every test

* LoggerController.spec.js

* Update schemas.spec.js

* finally fix transactions

* fix geopoint deadlock

* transaction with clean database

* batch.spec.js
@mtrezza mtrezza changed the title [WIP] Enable test suite to be randomized Enable test suite to be randomized Apr 4, 2021
@parseplatformorg
Copy link
Contributor

🎉 This change has been released in version 5.0.0-beta.1

@parseplatformorg parseplatformorg added the state:released-beta Released as beta version label Nov 1, 2021
@mtrezza mtrezza mentioned this pull request Mar 12, 2022
@parseplatformorg
Copy link
Contributor

🎉 This change has been released in version 5.0.0

@parseplatformorg parseplatformorg added the state:released Released as stable version label Mar 14, 2022
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-beta Released as beta version
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants