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: use testcontainers-go for clickhouse tests #1506

Merged
merged 6 commits into from
Aug 21, 2024

Conversation

mdelapenya
Copy link
Contributor

@mdelapenya mdelapenya commented Aug 20, 2024

Hello from the Testcontainers for Go community 👋!

This PR is a PoC for adopting testcontainers-go as the testing library for integration testing of the different storage integrations living in this project, for which we do have Go modules representing the majority of them. Please let me know if you have any concern about adding it, I'm really happy to assist in addressing them. Of course I'd understand any result for the PR.

What does this PR do?

This PR adds testcontainers-go to the Clickhouse module, updating the function that expects a local instance running on 127.0.0.1:9001 to be present on the system. Instead, testcontainers-go will start the instance from the test sourcecode.

Why is it important?

Less setup, as developers will just clone the repository and run the tests (given Docker or another container runtime 100% compatible is installed in the machine). Therefore, the CI experience is exactly the same as running the tests locally, which improves the debuggability.

As a side note, GH actions has Docker already installed, so it should work transparently.

How to test this PR?

Just go and do like the CI does:

cd ./clickhouse && go clean -testcache && go test ./... -v -race

Follow-up

If considered positively, add more PRs for the different storages.

Summary by CodeRabbit

Summary by CodeRabbit

  • Documentation

    • Enhanced the README.md with new sections on testing and local development, including requirements for Docker and usage of Testcontainers for integration tests.
    • Restructured the "Local development" section for improved clarity on setting up a Clickhouse cluster.
  • Tests

    • Improved the ClickHouse testing suite by integrating dynamic configuration for connection settings using Testcontainers, enhancing test reliability and flexibility.
    • Streamlined the GitHub Actions workflows by removing direct Clickhouse startup steps and introducing environment variables for image reference, simplifying the testing process.

@mdelapenya mdelapenya requested a review from a team as a code owner August 20, 2024 15:03
@mdelapenya mdelapenya requested review from gaby, sixcolors, ReneWerner87 and efectn and removed request for a team August 20, 2024 15:03
Copy link
Contributor

coderabbitai bot commented Aug 20, 2024

Walkthrough

The recent changes enhance the ClickHouse testing suite and documentation by introducing dynamic containerized testing and improving local development guidelines. A new "Running the tests" section in the README provides clear instructions for using Docker for integration tests, while the test suite has been updated to use Testcontainers. This results in a more flexible and reliable testing environment that adapts to various setups and simplifies workflow configuration.

Changes

Files Change Summary
clickhouse/README.md, clickhouse/... Added "Running the tests" section for Testcontainers usage, clarified local development instructions, and recommended using the Clickhouse Docker image.
clickhouse/clickhouse_test.go Integrated Testcontainers for dynamic ClickHouse instance setup, updated connection handling to avoid hardcoded values, and enhanced test functions for better flexibility.
.github/workflows/benchmark.yml, .github/workflows/test-clickhouse.yml Removed direct startup of Clickhouse service in workflows, introduced TEST_CLICKHOUSE_IMAGE environment variable to reference the Clickhouse image for consistency.

Poem

🐇 In the garden of code, we hop with delight,
New tests in containers, everything's right!
With Docker we play, in a world so vast,
No more fixed ports, our troubles are past.
So let’s celebrate, with a jump and a cheer,
For robust testing, we have nothing to fear! 🌼


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

clickhouse/README.md Outdated Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between eba6a80 and d604536.

Files ignored due to path filters (2)
  • clickhouse/go.mod is excluded by !**/*.mod
  • clickhouse/go.sum is excluded by !**/*.sum, !**/*.sum
Files selected for processing (2)
  • clickhouse/README.md (1 hunks)
  • clickhouse/clickhouse_test.go (11 hunks)
Additional comments not posted (6)
clickhouse/README.md (2)

34-37: LGTM: Clear instructions for running tests.

The "Running the tests" section clearly explains the use of Testcontainers for Go and the requirement for Docker.


Line range hint 38-48: LGTM: Practical guidance for local development.

The "Local development" section offers clear instructions on setting up a Clickhouse instance using Docker, which is useful for developers.

clickhouse/clickhouse_test.go (4)

4-14: LGTM: Necessary imports for Testcontainers integration.

The added imports are appropriate for the new test setup using Testcontainers and handling connection details.


16-20: LGTM: Centralized configuration constants.

Defining constants for Clickhouse configuration enhances readability and maintainability.


30-55: LGTM: Dynamic connection setup with Testcontainers.

The getTestConnection function now uses Testcontainers to dynamically start a Clickhouse instance, enhancing test flexibility and reliability.


Line range hint 57-187: LGTM: Updated test functions for portability.

The test functions now use the dynamic connection setup, ensuring they are not dependent on specific local configurations.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between d604536 and 6cd2a04.

Files selected for processing (1)
  • clickhouse/README.md (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • clickhouse/README.md

@gaby
Copy link
Member

gaby commented Aug 21, 2024

@mdelapenya Thank you for this, I'm a huge fan of TestContainers.

In the workflow yaml for Clickhouse you need to remove the ClickHouse instance we are starting else there will be two running.

Is there a way to get the clickhouse version from ENV? So that it's not hardcoded, or maybe use a major semver docker mage tag.

@mdelapenya
Copy link
Contributor Author

@mdelapenya Thank you for this, I'm a huge fan of TestContainers.

In the workflow yaml for Clickhouse you need to remove the ClickHouse instance we are starting else there will be two running.

Ah good catch! I'm fixing that immediately.

Is there a way to get the clickhouse version from ENV? So that it's not hardcoded, or maybe use a major semver docker mage tag.

Indeed, it's totally possible, although I see more work to do in the benchmarks workflow. Is there a reason to not include it for each storage file. My concern is about defining lots of env vars for each storage in the same step, instead of having them self-contained in the test code. Here:

- name: Run Benchmarks
        run: |
          set -o pipefail
          for d in */ ; do
            [[ $d == "tls/" ]] && continue
            [[ $d == "node_modules/" ]] && continue

            cd "$d"
            echo "Bench dir: $d"
            go test ./... -benchmem -run=^$ -bench . | tee -a ../output.txt
            cd ..
          done
        shell: bash
        env:
          MSSQL_DATABASE: master
          MSSQL_USERNAME: sa
          MSSQL_PASSWORD: MsSql!1234
          MYSQL_USERNAME: username
          MYSQL_PASSWORD: password
          MYSQL_DATABASE: fiber
          POSTGRES_DATABASE: fiber
          POSTGRES_USERNAME: username
          POSTGRES_PASSWORD: "pass#w%rd"

Do you think it's possible to move them to each storage's file? Will it affect the existing github checks, and their usages?

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 6cd2a04 and 91125ae.

Files selected for processing (3)
  • .github/workflows/benchmark.yml (2 hunks)
  • .github/workflows/test-clickhouse.yml (1 hunks)
  • clickhouse/clickhouse_test.go (11 hunks)
Files skipped from review due to trivial changes (1)
  • .github/workflows/benchmark.yml
Files skipped from review as they are similar to previous changes (1)
  • clickhouse/clickhouse_test.go
Additional comments not posted (1)
.github/workflows/test-clickhouse.yml (1)

28-29: Ensure the environment variable is utilized correctly.

The TEST_CLICKHOUSE_IMAGE environment variable is introduced to specify the Docker image for Clickhouse. Verify that this variable is correctly utilized within the test code to ensure that the intended Docker image is used during testing.

Ensure that the Clickhouse test code uses the TEST_CLICKHOUSE_IMAGE environment variable. You can verify this by searching for its usage in the codebase:

Verification successful

Environment variable TEST_CLICKHOUSE_IMAGE is correctly utilized.

The TEST_CLICKHOUSE_IMAGE environment variable is defined and used in the clickhouse/clickhouse_test.go file to retrieve the Docker image name from the environment. This ensures that the intended Docker image is used during testing, aligning with the changes made in the GitHub Actions workflow.

  • clickhouse/clickhouse_test.go: The environment variable is defined and used to fetch the image name.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of TEST_CLICKHOUSE_IMAGE in the Clickhouse test code.

# Test: Search for the environment variable usage. Expect: Occurrences where the variable is used.
rg --type go 'TEST_CLICKHOUSE_IMAGE'

Length of output: 225

@ReneWerner87
Copy link
Member

@gaby can you re-review

Copy link
Member

@gaby gaby left a comment

Choose a reason for hiding this comment

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

👍 LGTM

@mdelapenya
Copy link
Contributor Author

I do not see that error while running the benchmarks in my machine (MacOS M1). Any clue?

@gaby
Copy link
Member

gaby commented Aug 21, 2024

@mdelapenya We were just talking about that internally. The main go.mod file uses go1.20, but clickhouse requires go1.21 minimum.

The go.mod in storage/clickhouse uses 1.21.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 91125ae and 07d3b2e.

Files selected for processing (1)
  • .github/workflows/benchmark.yml (3 hunks)
Files skipped from review as they are similar to previous changes (1)
  • .github/workflows/benchmark.yml

@gaby
Copy link
Member

gaby commented Aug 21, 2024

@mdelapenya @ReneWerner87 CI is passing now.

@ReneWerner87 ReneWerner87 merged commit 01d0e07 into gofiber:main Aug 21, 2024
12 checks passed
@mdelapenya
Copy link
Contributor Author

Cool, thanks for merging this!

Do you have plan for adding testcontainers to the rest of the storages? I can create a tracking issue with the rest of them, so whoever wants to create a PR just needs to be assigned to it. Wdyt?

@gaby
Copy link
Member

gaby commented Aug 21, 2024

Cool, thanks for merging this!

Do you have plan for adding testcontainers to the rest of the storages? I can create a tracking issue with the rest of them, so whoever wants to create a PR just needs to be assigned to it. Wdyt?

Yes, go ahead and create the issue. Thank you! 💪

@mdelapenya mdelapenya deleted the testcontainers-go-clickhouse branch August 21, 2024 14:08
@mdelapenya
Copy link
Contributor Author

There it goes! #1507

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants