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

#4734 Use separate mock api for each test #4928

Merged
merged 73 commits into from Feb 1, 2023

Conversation

sosnovsky
Copy link
Collaborator

@sosnovsky sosnovsky commented Feb 1, 2023

This PR implements separate mock api for each test:

  • nodejs finds available port for new mock api
  • we create copy of extension build which uses new port
  • then this port is passed to tests using AvaContext

close #4734


Tests (delete all except exactly one):

  • Tests added or updated

To be filled by reviewers

I have reviewed that this PR... (tick whichever items you personally focused on during this review):

  • addresses the issue it closes (if any)
  • code is readable and understandable
  • is accompanied with tests, or tests are not needed
  • is free of vulnerabilities
  • is documented clearly and usefully, or doesn't need documentation

@sosnovsky sosnovsky marked this pull request as ready for review February 1, 2023 12:38
tomholub
tomholub previously approved these changes Feb 1, 2023
Copy link
Collaborator

@tomholub tomholub left a comment

Choose a reason for hiding this comment

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

👍 that's a lot of tests!

Looking good.

test/source/browser/browser-pool.ts Show resolved Hide resolved
test/source/browser/browser-pool.ts Show resolved Hide resolved
test/source/test.ts Outdated Show resolved Hide resolved
test/source/tests/tooling/index.ts Outdated Show resolved Hide resolved
@tomholub tomholub merged commit c8485e4 into master Feb 1, 2023
@tomholub tomholub deleted the feature/issue-4734-one-mock-per-test branch February 1, 2023 14:54
Copy link
Collaborator

@ioanmo226 ioanmo226 left a comment

Choose a reason for hiding this comment

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

Looks great 👍

@ioanmo226
Copy link
Collaborator

By the way, I can see that test sometimes fails with below error. Need to be investigated and fixed.

message: failed to log into google in newGoogleAcctAuthPromptThenAlertOrForward14:38
url: chrome-extension://clinllignhmgdgkljgkdckcebolglnbf/chrome/settings/index.htm?account_email=test-upd14:38
trace: Error: failed to log into google in newGoogleAcctAuthPromptThenAlertOrForward14:38
    at Catch.nameAndDetailsAsException (chrome-extension://clinllignhmgdgkljgkdckcebolglnbf/js/common/platform/catch.js:358:15)14:38
    at Catch.report (chrome-extension://clinllignhmgdgkljgkdckcebolglnbf/js/common/platform/catch.js:102:34)14:38
    at Settings.newGoogleAcctAuthPromptThenAlertOrForward (chrome-extension://clinllignhmgdgkljgkdckcebolglnbf/js/common/settings.js:388:27)14:38
    at async SettingsView.<anonymous> (chrome-extension://clinllignhmgdgkljgkdckcebolglnbf/chrome/settings/index.js:204:28)14:38
details:14:38
[typeof:object:[object Object]] {"result":"Error","error":"Grant successful but error accessing fc account: Error: Bad Request: 400 when GET-ing https://localhost:40743/shared-tenant-fes/api/v1/client-configuration?domain=settings.flowcrypt.test (no body):  -> Test error","acctEmail":"test-update@settings.flowcrypt.test"}14:38
### Catch.reportErr calling stack ###14:38
#     at Catch.formatExceptionForReport (chrome-extension://clinllignhmgdgkljgkdckcebolglnbf/js/common/platform/catch.js:272:90)14:38
#     at Catch.onErrorInternalHandler (chrome-extension://clinllignhmgdgkljgkdckcebolglnbf/js/common/platform/catch.js:80:29)14:38
#     at Catch.reportErr (chrome-extension://clinllignhmgdgkljgkdckcebolglnbf/js/common/platform/catch.js:96:18)14:38
#     at Catch.report (chrome-extension://clinllignhmgdgkljgkdckcebolglnbf/js/common/platform/catch.js:102:18)14:38
#     at Settings.newGoogleAcctAuthPromptThenAlertOrForward (chrome-extension://clinllignhmgdgkljgkdckcebolglnbf/js/common/settings.js:388:27)14:38
#     at async SettingsView.<anonymous> (chrome-extension://clinllignhmgdgkljgkdckcebolglnbf/chrome/settings/index.js:204:28)14:38
# 14:38
# url: chrome-extension://clinllignhmgdgkljgkdckcebolglnbf/chrome/settings/index.htm?account_email=test-update@settings.flowcrypt.test

@sosnovsky
Copy link
Collaborator Author

By the way, I can see that test sometimes fails with below error. Need to be investigated and fixed.

@ioanmo226 I think it happened once, test passes well now, but let's monitor if it'll fail in the future.
Sometimes there was an issue with test execution time limit, I increased it a bit, seems like it's enough for now.

"test_ci_chrome_consumer_live_gmail": "npx ava --timeout=20m --verbose --concurrency=10 build/test/test/source/test.js -- CONSUMER-LIVE-GMAIL STANDARD-GROUP",
"test_ci_chrome_consumer": "npx ava --timeout=20m --verbose --concurrency=10 build/test/test/source/test.js -- CONSUMER-MOCK STANDARD-GROUP",
"test_ci_chrome_enterprise": "npx ava --timeout=20m --verbose --concurrency=10 build/test/test/source/test.js -- ENTERPRISE-MOCK STANDARD-GROUP",
"test_ci_chrome_consumer_flaky": "npx ava --timeout=20m --verbose --concurrency=10 build/test/test/source/test.js -- CONSUMER-MOCK FLAKY-GROUP",
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the purpose of the "flaky" group? These are resource-demanding tests or tests with unstable performance. This group is meant for tests to be run consequently, one at a time

Copy link
Collaborator

Choose a reason for hiding this comment

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

Some tests are inexplicably resource-demanding. When run in parallel with other tests, what can happen is that either that test will time out, or other tests will fail while the resource-intensive test hogs up resources.

Other reason that a test may end up in "flaky" section is if it needs to be executed serially for some other reason.

Generally speaking, these tests tend to cause reliability trouble when executed in parallel, for one reason or another.

Of course, they could be debugged and fixed one by one and moved, possibly, if we had the time or willingness.

Copy link
Contributor

Choose a reason for hiding this comment

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

Does this mean we should set --concurrency=1 instead of --concurrency=10?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, we can change it back to --concurrency=1 as browser pool size is automatically set to 1 for FLAKY-GROUP - https://github.com/FlowCrypt/flowcrypt-browser/blob/master/test/source/util/index.ts#L31

Copy link
Collaborator

Choose a reason for hiding this comment

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

Shouldn't browser pool and concurrency always be exactly equal? Or is there a reason to have these two numbers diverge? I'd imagine, we could remove special code to choose that FLAKY-GROUP has 1 in the pool, and instead follow whatever the provided --concurrency ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Probably it can be simplified, as currently --pool-size parameter is used for determining oneIfNotPooled, which then also used for setting ATTEMPTS constant - https://github.com/FlowCrypt/flowcrypt-browser/blob/master/test/source/test.ts#L40

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

BUILD_PATH=./build/test/mock-builds/port-$2-$(openssl rand -hex 12)
mkdir -p $BUILD_PATH
cp -r ./$1/* $BUILD_PATH
grep ":8001" $BUILD_PATH -lr | xargs sed -i.bak -e "s/\:8001/\:$2/g"
Copy link
Contributor

Choose a reason for hiding this comment

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

Can it be solved with a [BUILD_REPLACEABLE_....] placeholder?

Copy link
Collaborator

@tomholub tomholub Feb 13, 2023

Choose a reason for hiding this comment

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

I suppose it could.. we would still need to do two rounds of replacing? The step that normally replaces [BUILD_REPLACEABLE_....] and currently puts the :8001 would still need to insert some more maybe [TEST_REPLACEABLE_MOCK_PORT] and then that would be replaced here.

It's true that as things are now, there is no meaning to the :8001 in particular. So that should not be put in, to not be confusing. So [TEST_REPLACEABLE_MOCK_PORT] or similar would be a better choice here.

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.

one mock instance per test
4 participants