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: add E2E tests for chromium and firefox #1121

Merged
merged 11 commits into from
Jan 17, 2023
Merged

feat: add E2E tests for chromium and firefox #1121

merged 11 commits into from
Jan 17, 2023

Conversation

galargh
Copy link
Contributor

@galargh galargh commented Dec 19, 2022

Description

This PR adds a setup for E2E testing to ipfs-companion.

The environment setup is automated using docker compose. The environment consists of:

  • firefox container
  • chrome container
  • kubo container
  • e2e container where the tests are executed from

The tests check the following for firefox and chromium:

  • can the extension be installed?
  • can api/gateway URL be modified?
  • is the number of connected peers correctly reported?
  • is the number of connected peers greater than 0?

The tests follow the proposed testing procedure from https://github.com/ipfs/kubo/blob/master/docs/RELEASE_ISSUE_TEMPLATE.md.

The newly added tests can be executed through GitHub Actions.

Testing
TODO
  • create GHA workflow for running E2E tests; proposed inputs
    • firefox/chromium versions
    • ipfs-companion version; proposed behaviours
      • build from source
      • download from releases
    • kubo version
  • add description

@welcome
Copy link

welcome bot commented Dec 19, 2022

Thank you for submitting this PR!
A maintainer will be here shortly to review it.
We are super grateful, but we are also overloaded! Help us by making sure that:

  • The context for this PR is clear, with relevant discussion, decisions
    and stakeholders linked/mentioned.

  • Your contribution itself is clear (code comments, self-review for the
    rest) and in its best form. Follow the code contribution
    guidelines

    if they apply.

Getting other community members to do a review would be great help too on complex PRs (you can ask in the chats/forums). If you are unsure about something, just leave us a comment.
Next steps:

  • A maintainer will triage and assign priority to this PR, commenting on
    any missing things and potentially assigning a reviewer for high
    priority items.

  • The PR gets reviews, discussed and approvals as needed.

  • The PR is merged by maintainers when it has been approved and comments addressed.

We currently aim to provide initial feedback/triaging within seven business days. Please keep an eye on any labelling actions, as these will indicate priorities and status of your contribution.
We are very grateful for your contribution!

@galargh galargh changed the title feat: add E2E tests for chromium and firefox [WIP] feat: add E2E tests for chromium and firefox Dec 19, 2022
@galargh galargh changed the title [WIP] feat: add E2E tests for chromium and firefox feat: add E2E tests for chromium and firefox Dec 20, 2022
@galargh galargh marked this pull request as ready for review December 20, 2022 10:09
Copy link
Contributor

@whizzzkid whizzzkid left a comment

Choose a reason for hiding this comment

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

Thanks for creating this PR @galargh, excellent work! I have some concerns regarding the use of selenium vs playwright and some ideas for improvements (marked as [opt]) those can be looked into later if you'd like!

Cheers :)

Comment on lines 4 to 5
ipfs config --json API.HTTPHeaders.Access-Control-Allow-Origin '["*"]'
ipfs config --json API.HTTPHeaders.Access-Control-Allow-Methods '["*"]'
Copy link
Contributor

Choose a reason for hiding this comment

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

[opt] Question: won't this be detrimental to the e2e spirit of testing companion? If we're configuring the API to work for all origins, we might not catch a few issues.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Anything in particular we're concerned with? The reason why this is needed is because in the "everything in docker" setup, the browsers run in different containers than kubo. There might be another way to do it. This was just the one that required the least thought.

Copy link
Contributor

Choose a reason for hiding this comment

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

yes, kubo has support for specific user agents, which includes ipfs-companion since ipfs/kubo#8690

This is not normal user behaviour, which means we can have cases where tests pass but the users don't see this behaviour. That'll defeat the purpose of e2e testing.

ci/download-release-artifacts.sh Outdated Show resolved Hide resolved
docker-compose.e2e.yml Outdated Show resolved Hide resolved
package.json Show resolved Hide resolved
package.json Show resolved Hide resolved
test/e2e/ipfs-companion.test.js Outdated Show resolved Hide resolved
test/e2e/ipfs-companion.test.js Show resolved Hide resolved
test/e2e/ipfs-companion.test.js Outdated Show resolved Hide resolved
test/e2e/ipfs-companion.test.js Outdated Show resolved Hide resolved
test/e2e/ipfs-companion.test.js Outdated Show resolved Hide resolved
@SgtPooki
Copy link
Member

I would also like to voice my preference of playwright over selenium.

  1. We're using playwright with all of our projects
  2. Selenium is historically unstable during runtime and maintenance. I've got experience with building & maintaining an e2e library backed by selenium, and I am not a fan.

Copy link
Contributor

@whizzzkid whizzzkid left a comment

Choose a reason for hiding this comment

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

Thanks! I would like @lidel to weigh in on selenium vs playwright, everything else LGTM! 🚀

Comment on lines 4 to 5
ipfs config --json API.HTTPHeaders.Access-Control-Allow-Origin '["*"]'
ipfs config --json API.HTTPHeaders.Access-Control-Allow-Methods '["*"]'
Copy link
Contributor

Choose a reason for hiding this comment

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

yes, kubo has support for specific user agents, which includes ipfs-companion since ipfs/kubo#8690

This is not normal user behaviour, which means we can have cases where tests pass but the users don't see this behaviour. That'll defeat the purpose of e2e testing.

ci/download-release-artifacts.sh Outdated Show resolved Hide resolved
docker-compose.e2e.yml Outdated Show resolved Hide resolved
package.json Show resolved Hide resolved
package.json Show resolved Hide resolved
test/e2e/ipfs-companion.test.js Show resolved Hide resolved
@galargh
Copy link
Contributor Author

galargh commented Dec 22, 2022

I would also like to voice my preference of playwright over selenium.

  1. We're using playwright with all of our projects
  2. Selenium is historically unstable during runtime and maintenance. I've got experience with building & maintaining an e2e library backed by selenium, and I am not a fan.

Personally, I don't know enough about either to prefer one over the other BUT it seems we cannot accomplish the task at all in playwright at the moment because of lack of support for Firefox extensions (microsoft/playwright#7297).

@SgtPooki
Copy link
Member

it seems we cannot accomplish the task at all in playwright

ACK. makes complete sense.

Copy link
Member

@SgtPooki SgtPooki left a comment

Choose a reason for hiding this comment

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

Approving with comments.. thanks a ton for putting this together @galargh

.github/workflows/e2e.yml Show resolved Hide resolved
.github/workflows/e2e.yml Show resolved Hide resolved
.github/workflows/e2e.yml Show resolved Hide resolved
.github/workflows/e2e.yml Show resolved Hide resolved
ci/download-release-artifacts.sh Outdated Show resolved Hide resolved
test/e2e/ipfs-companion.test.js Show resolved Hide resolved
test/e2e/ipfs-companion.test.js Outdated Show resolved Hide resolved

const peers = await getNumberOfConnectedPeers(browser, url)

expect(peers).not.to.equal(0)
Copy link
Member

Choose a reason for hiding this comment

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

I feel like this will be flaky unless we have a guaranteed peer running in CI as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can add one if that becomes a problem.

Copy link
Contributor Author

@galargh galargh Jan 17, 2023

Choose a reason for hiding this comment

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

I created #1131 for this

test/e2e/ipfs-companion.test.js Outdated Show resolved Hide resolved
test/e2e/ipfs-companion.test.js Outdated Show resolved Hide resolved
@SgtPooki
Copy link
Member

@galargh , the only thing I would really like to see before merge is an update to README.md or docs/DEVELOPER-NOTES.md informing users how to run this locally, how to debug, etc.

@SgtPooki SgtPooki self-requested a review January 14, 2023 00:18
Copy link
Member

@SgtPooki SgtPooki left a comment

Choose a reason for hiding this comment

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

When attempting to run locally, I ran into some issues:

npm run clean
npm i
npm run release-build # Error when running this

Error output

 => [3/9] RUN mkdir -p /home/node/app                                                                                                         0.2s
 => ERROR [4/9] RUN if [ 501 -ne 0 ] && [ 20 -ne 0 ]; then     userdel -f node &&     if getent group node ; then groupdel node; fi &&     g  0.3s
------
 > [4/9] RUN if [ 501 -ne 0 ] && [ 20 -ne 0 ]; then     userdel -f node &&     if getent group node ; then groupdel node; fi &&     groupadd -g 20 node &&     useradd -l -u 501 -g node node &&     chown -fhR 501:20 /home/node; fi:
#8 0.255 groupadd: GID '20' already exists
------
executor failed running [/bin/sh -c if [ ${USER_ID:-0} -ne 0 ] && [ ${GROUP_ID:-0} -ne 0 ]; then     userdel -f node &&     if getent group node ; then groupdel node; fi &&     groupadd -g ${GROUP_ID} node &&     useradd -l -u ${USER_ID} -g node node &&     chown -fhR ${USER_ID}:${GROUP_ID} /home/node; fi]: exit code: 4

commenting out all the user modifications allows it to work. What is that code supposed to be doing? can we make it smarter?

IPFS_COMPANION_VERSION: ${{ inputs.ipfs-companion-version }}
- name: Build ipfs-companion
if: inputs.ipfs-companion-version == ''
run: npm run release-build
Copy link
Member

Choose a reason for hiding this comment

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

we should eventually upload the built docker image (ipfs-companion-release-build) and reuse that if possible.. (hash of source or non-docker build artifacts to determine if we want to use the same image?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did a write-up recently on docker publishing/caching in CI for build speed-up. See https://filecoinproject.slack.com/archives/C03KLC57LKB/p1673517809976679?thread_ts=1673468796.401379&cid=C03KLC57LKB

I'd say it's a little bit beyond the scope of this PR though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I created #1132 for this

SgtPooki and others added 3 commits January 13, 2023 16:44
- replace fixed delays with exponential backoff
- make download-release-artifacts.sh work even if build dir already exists
- document how to run e2e tests locally
- delete user/group if it already exists during release build in docker
- make it easier to add new e2e test cases in the future
Copy link
Contributor Author

@galargh galargh left a comment

Choose a reason for hiding this comment

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

@galargh , the only thing I would really like to see before merge is an update to README.md or docs/DEVELOPER-NOTES.md informing users how to run this locally, how to debug, etc.

Docs added to docs/DEVELOPER-NOTES.md.

When attempting to run locally, I ran into some issues.

I added deleting user/group if it already exists to the Dockerfile which should fix the issue. I suspect it's there to maintain correct ownership of built files after we get them out of the docker container.

.github/workflows/e2e.yml Show resolved Hide resolved
.github/workflows/e2e.yml Show resolved Hide resolved
.github/workflows/e2e.yml Show resolved Hide resolved
.github/workflows/e2e.yml Show resolved Hide resolved
IPFS_COMPANION_VERSION: ${{ inputs.ipfs-companion-version }}
- name: Build ipfs-companion
if: inputs.ipfs-companion-version == ''
run: npm run release-build
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did a write-up recently on docker publishing/caching in CI for build speed-up. See https://filecoinproject.slack.com/archives/C03KLC57LKB/p1673517809976679?thread_ts=1673468796.401379&cid=C03KLC57LKB

I'd say it's a little bit beyond the scope of this PR though.

@@ -0,0 +1,40 @@
version: "3.9"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure how exactly setting hostname and domainname works. Could you elaborate on how they could affect the setup?


const peers = await getNumberOfConnectedPeers(browser, url)

expect(peers).not.to.equal(0)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can add one if that becomes a problem.

@galargh galargh requested a review from SgtPooki January 16, 2023 15:33
Copy link
Member

@SgtPooki SgtPooki left a comment

Choose a reason for hiding this comment

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

lgtm.. a few comments unaddressed, but a significant improvement. Thanks @galargh !

docs/DEVELOPER-NOTES.md Show resolved Hide resolved
test/e2e/ipfs-companion.test.js Show resolved Hide resolved
test/e2e/ipfs-companion.test.js Show resolved Hide resolved
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.

3 participants