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

chore: adopt testcontainers-go for Postgres, MySQL, MSSQL and MongoDB #1515

Open
wants to merge 26 commits into
base: main
Choose a base branch
from

Conversation

mdelapenya
Copy link
Contributor

@mdelapenya mdelapenya commented Aug 29, 2024

What does this PR do?

  • chore: use testcontainers-go in mongodb store
  • chore: use testcontainers-go in mssql store
  • chore: use testcontainers-go in mysql store
  • chore: use testcontainers-go in postgres store

It uses testcontainers-go in the integration tests for the given stores, refactoring the tests to always consume a new test store, backed by a Docker container.

WHy is it important?

Reproducibility: any developer will be able to run the tests locally exactly equals as in the Github Actions.

Related issues

For reference, please check out previous work for Couchbase and Minio (#1508) and ClickHouse (#1506)

There is more ongoing work, as defined in #1507

Summary by CodeRabbit

  • New Features

    • Updated testing workflows to utilize the latest Docker images for MongoDB, MSSQL, MySQL, PostgreSQL, ClickHouse, Couchbase, and MinIO.
    • Introduced new environment variables for improved configurability of database images during testing.
  • Bug Fixes

    • Enhanced test reliability by ensuring each test case initializes its own database connection, preventing state leakage.
  • Refactor

    • Streamlined test setup processes by replacing static store variables with dynamic initialization functions across all database tests.
    • Added cleanup procedures in test functions to manage resources effectively.

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

coderabbitai bot commented Aug 29, 2024

Walkthrough

The changes involve significant modifications to the GitHub Actions workflow files and associated test files for various database services, including MongoDB, MSSQL, MySQL, PostgreSQL, ClickHouse, Couchbase, and MinIO. The updates include the removal of service configurations and the introduction of environment variables for updated Docker images. Additionally, resource management improvements have been made across multiple test files to enhance test isolation and reliability.

Changes

Files Change Summary
.github/workflows/benchmark.yml Removed configurations for MongoDB, MSSQL, MySQL, and PostgreSQL services; added environment variables for updated images.
.github/workflows/test-couchbase.yml Updated TEST_COUCHBASE_IMAGE from 7.1.1 to 7.6.3.
couchbase/couchbase_test.go Updated default Couchbase image; added defer testStore.Close() statements for resource management across multiple tests.

Possibly related PRs

Suggested labels

🧹 Updates

🐰 In a world of code and tests so bright,
I hop with joy, what a splendid sight!
New images and functions, oh what a cheer,
My database friends are now crystal clear!
With each new store, fresh and anew,
Testing's a breeze, oh how we grew! 🐇✨


Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 43a47ef and a4849c8.

Files selected for processing (3)
  • .github/workflows/benchmark.yml (1 hunks)
  • .github/workflows/test-couchbase.yml (1 hunks)
  • couchbase/couchbase_test.go (11 hunks)
Additional comments not posted (14)
.github/workflows/test-couchbase.yml (1)

30-30: LGTM! Verify the impact on the Couchbase tests.

The upgrade to Couchbase image version 7.6.3 aligns with the PR objective of adopting testcontainers-go for various database stores. This change may introduce bug fixes, performance improvements, or new features relevant to the testing process.

Please ensure that the Couchbase tests are run successfully with the updated image version and verify that the test results are as expected. If necessary, update the test code or configuration to maintain compatibility with the new version.

Run the following script to verify the Couchbase tests:

Verification successful

LGTM! The Couchbase image update appears to be properly implemented.

The upgrade to Couchbase image version 7.6.3 has been consistently applied in both the GitHub Actions workflow and the test file (couchbase_test.go). The main implementation (couchbase.go) doesn't contain any version-specific code, which helps maintain compatibility. The use of testcontainers-go in the tests aligns with the PR objective.

No other files contain version-specific Couchbase configurations, reducing the risk of incompatibilities. The change is well-isolated to the test environment and CI/CD pipeline, which is the correct approach for this type of update.

To ensure everything works as expected, please run the Couchbase tests in your local development environment and verify that all tests pass with the updated image version.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the Couchbase tests with the updated image version.

# Test: Run the Couchbase tests and check the exit code. Expect: Exit code 0 (success).
cd ./couchbase && go test ./... -v -race
echo "Couchbase tests exit code: $?"

Length of output: 182


Script:

#!/bin/bash
# Search for Couchbase-related files and their contents

# Find Couchbase-related files
echo "Couchbase-related files:"
fd -t f -e go -e yml -e yaml -e json couchbase

# Search for Couchbase version references in Go files
echo -e "\nCouchbase version references in Go files:"
rg -n "couchbase.*7\.[0-9]+" --type go

# Search for Couchbase configuration in YAML files
echo -e "\nCouchbase configuration in YAML files:"
rg -n "couchbase:.*7\.[0-9]+" --type yaml

# Check for recent changes in Couchbase-related files
echo -e "\nRecent changes in Couchbase-related files:"
git log -n 5 --pretty=format:"%h - %s" --grep="couchbase"

# Look for Couchbase-related test files
echo -e "\nCouchbase-related test files:"
fd -t f -e go test.*couchbase

Length of output: 980


Script:

#!/bin/bash
# Examine Couchbase-related files for version-specific code and configurations

# Display contents of couchbase.go
echo "Contents of couchbase.go:"
cat couchbase/couchbase.go

echo -e "\n----------------------------------------\n"

# Display contents of couchbase_test.go
echo "Contents of couchbase_test.go:"
cat couchbase/couchbase_test.go

echo -e "\n----------------------------------------\n"

# Search for YAML files in the repository
echo "YAML files in the repository:"
find . -name "*.yml" -o -name "*.yaml"

echo -e "\n----------------------------------------\n"

# Search for Couchbase configuration in all files (not just YAML)
echo "Couchbase configuration in all files:"
grep -r -n "couchbase:.*7\.[0-9]+" .

Length of output: 10654

.github/workflows/benchmark.yml (2)

113-113: LGTM!

The TEST_COUCHBASE_IMAGE environment variable is correctly set to a specific Couchbase Enterprise release version, which helps ensure reproducible test environments.


115-118: Verify application compatibility with the updated database versions.

The environment variables for the database images used in testing have been updated to use the latest stable versions, which is a good practice for keeping the test environment up to date.

However, it's crucial to ensure that the application code is compatible with these updated versions, as there may be changes in behavior or performance characteristics. I recommend thoroughly testing the application against these database versions to identify and address any potential issues.

couchbase/couchbase_test.go (11)

15-15: LGTM!

Updating the default Couchbase image to a newer version is a good practice to ensure the tests run against a more recent and stable release.


42-46: LGTM!

Adding a cleanup function to terminate the Couchbase container after each test is a good practice for proper resource management and test isolation.


64-64: LGTM!

Adding a defer testStore.Close() statement is a good practice to ensure proper resource management and prevent potential leaks.


74-74: LGTM!

Adding a defer testStore.Close() statement is a good practice to ensure proper resource management and prevent potential leaks.


85-85: LGTM!

Adding a defer testStore.Close() statement is a good practice to ensure proper resource management and prevent potential leaks.


99-99: LGTM!

Adding a defer testStore.Close() statement is a good practice to ensure proper resource management and prevent potential leaks.


115-115: LGTM!

Adding a defer testStore.Close() statement is a good practice to ensure proper resource management and prevent potential leaks.


130-130: LGTM!

Adding a defer testStore.Close() statement is a good practice to ensure proper resource management and prevent potential leaks.


146-146: LGTM!

Replacing testStore.Close() with require.NoError(t, testStore.Close()) is a good practice to ensure that closing the test store does not return an error, enhancing the test's reliability.


152-152: LGTM!

Adding a defer testStore.Close() statement is a good practice to ensure proper resource management and prevent potential leaks.


160-160: LGTM!

Adding defer testStore.Close() statements in the benchmark functions is a good practice to ensure proper resource management and prevent potential leaks.

Also applies to: 175-175, 193-193


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>, please review it.
    -- 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    -- @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 using 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.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @coderabbitai title anywhere in the PR title to generate the title automatically.

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.

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 2f1c0cb and 2f5263e.

Files ignored due to path filters (8)
  • mongodb/go.mod is excluded by !**/*.mod
  • mongodb/go.sum is excluded by !**/*.sum, !**/*.sum
  • mssql/go.mod is excluded by !**/*.mod
  • mssql/go.sum is excluded by !**/*.sum, !**/*.sum
  • mysql/go.mod is excluded by !**/*.mod
  • mysql/go.sum is excluded by !**/*.sum, !**/*.sum
  • postgres/go.mod is excluded by !**/*.mod
  • postgres/go.sum is excluded by !**/*.sum, !**/*.sum
Files selected for processing (9)
  • .github/workflows/benchmark.yml (2 hunks)
  • .github/workflows/test-mongodb.yml (2 hunks)
  • .github/workflows/test-mssql.yml (2 hunks)
  • .github/workflows/test-mysql.yml (2 hunks)
  • .github/workflows/test-postgres.yml (2 hunks)
  • mongodb/mongodb_test.go (11 hunks)
  • mssql/mssql_test.go (12 hunks)
  • mysql/mysql_test.go (13 hunks)
  • postgres/postgres_test.go (12 hunks)
Additional comments not posted (32)
.github/workflows/test-mysql.yml (1)

30-31: LGTM!

The introduction of the TEST_MYSQL_IMAGE environment variable is a good practice to ensure consistency and reliability in the testing environment.

.github/workflows/test-mongodb.yml (2)

19-20: LGTM!

Updating the Go version matrix to include newer versions is a good practice to ensure compatibility and performance with the latest Go versions.


30-30: LGTM!

The introduction of the TEST_MONGODB_IMAGE environment variable is a good practice to ensure consistency and reliability in the testing environment.

.github/workflows/test-postgres.yml (1)

30-31: LGTM!

The introduction of the TEST_POSTGRES_IMAGE environment variable is a good practice to ensure consistency and reliability in the testing environment.

.github/workflows/test-mssql.yml (1)

30-31: LGTM!

The addition of the environment variable TEST_MSSQL_IMAGE is correct and aligns with the PR objective.

.github/workflows/benchmark.yml (4)

118-118: LGTM!

The addition of the environment variable TEST_MONGODB_IMAGE is correct and aligns with the PR objective.


119-119: LGTM!

The addition of the environment variable TEST_MSSQL_IMAGE is correct and aligns with the PR objective.


120-120: LGTM!

The addition of the environment variable TEST_MYSQL_IMAGE is correct and aligns with the PR objective.


121-121: LGTM!

The addition of the environment variable TEST_POSTGRES_IMAGE is correct and aligns with the PR objective.

mongodb/mongodb_test.go (10)

10-10: LGTM!

The import statement for testcontainers-go/modules/mongodb is correct and necessary for using the testcontainers-go library for MongoDB.


13-19: LGTM!

The constant block for MongoDB image and credentials is correctly defined and aligns with the PR objective.


21-44: LGTM!

The newTestStore function is correctly implemented and improves the isolation of tests by ensuring that each test starts with a fresh instance of the MongoDB store.


53-55: LGTM!

The modification of the Test_MongoDB_Set function to use newTestStore is correct and aligns with the PR objective.


66-68: LGTM!

The modification of the Test_MongoDB_Set_Override function to use newTestStore is correct and aligns with the PR objective.


82-84: LGTM!

The modification of the Test_MongoDB_Get function to use newTestStore is correct and aligns with the PR objective.


100-102: LGTM!

The modification of the Test_MongoDB_Set_Expiration function to use newTestStore is correct and aligns with the PR objective.


112-114: LGTM!

The modification of the Test_MongoDB_Get_Expired function to use newTestStore is correct and aligns with the PR objective.


121-123: LGTM!

The modification of the Test_MongoDB_Get_NotExist function to use newTestStore is correct and aligns with the PR objective.


135-137: LGTM!

The modification of the Test_MongoDB_Delete function to use newTestStore is correct and aligns with the PR objective.

mssql/mssql_test.go (4)

4-11: LGTM!

The import statements are correct and necessary for the functionality.


14-21: LGTM!

The constants improve configurability and readability.


23-51: LGTM!

The function is correctly implemented and ensures each test runs in isolation with a fresh database connection.


Line range hint 59-264: LGTM!

The updates ensure that each test retrieves its own instance of the storage, improving test isolation and reliability.

mysql/mysql_test.go (5)

4-11: LGTM!

The import statements are correct and necessary for the functionality.


14-21: LGTM!

The constants improve configurability and readability.


23-39: LGTM!

The function is correctly implemented and ensures each test runs in isolation with a fresh database connection.


41-57: LGTM!

The function is correctly implemented and ensures the MySQL container is properly configured and started.


Line range hint 59-294: LGTM!

The updates ensure that each test retrieves its own instance of the storage, improving test isolation and reliability.

postgres/postgres_test.go (4)

Line range hint 4-13: LGTM!

The import statements are correct and necessary for the functionality.


16-23: LGTM!

The constants improve configurability and readability.


25-56: LGTM!

The function is correctly implemented and ensures each test runs in isolation with a fresh database connection.


Line range hint 64-282: LGTM!

The updates ensure that each test retrieves its own instance of the storage, improving test isolation and reliability.

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 2f5263e and 689759c.

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

mongodb/go.mod Outdated Show resolved Hide resolved
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.

Small comment

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 689759c and de8f798.

Files ignored due to path filters (2)
  • mongodb/go.mod is excluded by !**/*.mod
  • postgres/go.mod is excluded by !**/*.mod
Files selected for processing (3)
  • .github/workflows/test-mssql.yml (2 hunks)
  • .github/workflows/test-mysql.yml (2 hunks)
  • .github/workflows/test-postgres.yml (2 hunks)
Files skipped from review as they are similar to previous changes (2)
  • .github/workflows/test-mssql.yml
  • .github/workflows/test-postgres.yml
Additional comments not posted (4)
.github/workflows/test-mysql.yml (4)

19-19: LGTM!

The addition of Go version 1.22.x to the matrix is appropriate.


20-20: LGTM!

The addition of Go version 1.23.x to the matrix is appropriate.


30-30: LGTM!

Setting the TEST_MYSQL_IMAGE environment variable to docker.io/mysql:9 ensures consistency and reliability in the testing environment.


31-31: LGTM!

Running the tests with the specified MySQL image is appropriate.

@mdelapenya
Copy link
Contributor Author

For some reason, the memcache service is failing in the benchmark job. Any guess?

@ReneWerner87
Copy link
Member

sorry overlooked, that's really strange, I'll have to take a look at it in the next few days

@mdelapenya
Copy link
Contributor Author

@ReneWerner87 any update on the benchmark thing? 🙏 Once merge, I can send a new PR with more stores

@ReneWerner87
Copy link
Member

unfortunately haven't had time to look yet, will have a look on sunday and fix it then, but feel free to make pull requests for the other stores if you like

in this case we only have to apply the fix to the other PR

@ReneWerner87
Copy link
Member

ReneWerner87 commented Sep 15, 2024

@mdelapenya now the reason

you removed the other services

image

now the options from postgres for the health check belongs to memcached

image

but there is no postgres started

image

other question
do we have to change the golang versions in the test-*.yml's and go.mod files?
then we would cause a breaking change as in the previous PR request
#1508 (comment)

@ReneWerner87
Copy link
Member

Ok, 1.21 is ok for me

@mdelapenya
Copy link
Contributor Author

Couchbase benchmark is passing for me locally 🤔 Any clue?

@ReneWerner87
Copy link
Member

Will check it tomorrow morning

@ReneWerner87
Copy link
Member

i restarted the benchmarks and now we have a new problem

image

@mdelapenya
Copy link
Contributor Author

taking a look, thanks! 🙏

@mdelapenya
Copy link
Contributor Author

It's weird: they pass locally for me

go test ./... -v -benchmem -run=^$ -bench . | tee -a ../output.txt
goos: darwin
goarch: arm64
pkg: github.com/gofiber/storage/mssql/v2
Benchmark_MSSQL_Set
2024/09/17 15:38:33 github.com/testcontainers/testcontainers-go - Connected to docker: 
  Server Version: 82+testcontainerscloud (via Testcontainers Desktop 1.17.0)
  API Version: 1.46
  Operating System: Ubuntu 22.04.4 LTS
  Total Memory: 15779 MB
  Testcontainers for Go Version: v0.33.0
  Resolved Docker Host: tcp://127.0.0.1:51475
  Resolved Docker Socket Path: /var/run/docker.sock
  Test SessionID: c134e29f4f160c5036506bb926bfd5fef0252e721d3b872da882ac66e699aebd
  Test ProcessID: f85ff9e5-c073-473d-9c5f-10b48aadf30a
2024/09/17 15:38:33 🐳 Creating container for image testcontainers/ryuk:0.8.1
2024/09/17 15:38:33 ✅ Container created: 898ef11dd444
2024/09/17 15:38:33 🐳 Starting container: 898ef11dd444
2024/09/17 15:38:34 ✅ Container started: 898ef11dd444
2024/09/17 15:38:34 ⏳ Waiting for container id 898ef11dd444 image: testcontainers/ryuk:0.8.1. Waiting for: &{Port:8080/tcp timeout:<nil> PollInterval:100ms skipInternalCheck:false}
2024/09/17 15:38:34 🔔 Container is ready: 898ef11dd444
2024/09/17 15:38:34 🐳 Creating container for image mcr.microsoft.com/mssql/server:2022-RTM-GDR1-ubuntu-20.04
2024/09/17 15:38:34 ✅ Container created: 60c8ace27308
2024/09/17 15:38:34 🐳 Starting container: 60c8ace27308
2024/09/17 15:38:34 ✅ Container started: 60c8ace27308
2024/09/17 15:38:34 ⏳ Waiting for container id 60c8ace27308 image: mcr.microsoft.com/mssql/server:2022-RTM-GDR1-ubuntu-20.04. Waiting for: &{timeout:<nil> Log:Recovery is complete. IsRegexp:false Occurrence:1 PollInterval:100ms}
2024/09/17 15:38:39 🔔 Container is ready: 60c8ace27308
2024/09/17 15:38:40 🐳 Creating container for image mcr.microsoft.com/mssql/server:2022-RTM-GDR1-ubuntu-20.04
2024/09/17 15:38:40 ✅ Container created: 16ebc0c630be
2024/09/17 15:38:40 🐳 Starting container: 16ebc0c630be
2024/09/17 15:38:40 ✅ Container started: 16ebc0c630be
2024/09/17 15:38:40 ⏳ Waiting for container id 16ebc0c630be image: mcr.microsoft.com/mssql/server:2022-RTM-GDR1-ubuntu-20.04. Waiting for: &{timeout:<nil> Log:Recovery is complete. IsRegexp:false Occurrence:1 PollInterval:100ms}
2024/09/17 15:38:45 🔔 Container is ready: 16ebc0c630be
Benchmark_MSSQL_Set-8                          6         191780180 ns/op           99942 B/op        598 allocs/op
Benchmark_MSSQL_Get
2024/09/17 15:38:47 🐳 Creating container for image mcr.microsoft.com/mssql/server:2022-RTM-GDR1-ubuntu-20.04
2024/09/17 15:38:47 ✅ Container created: dbb74231c3b6
2024/09/17 15:38:47 🐳 Starting container: dbb74231c3b6
2024/09/17 15:38:47 ✅ Container started: dbb74231c3b6
2024/09/17 15:38:47 ⏳ Waiting for container id dbb74231c3b6 image: mcr.microsoft.com/mssql/server:2022-RTM-GDR1-ubuntu-20.04. Waiting for: &{timeout:<nil> Log:Recovery is complete. IsRegexp:false Occurrence:1 PollInterval:100ms}
2024/09/17 15:38:52 🔔 Container is ready: dbb74231c3b6
2024/09/17 15:38:53 🐳 Creating container for image mcr.microsoft.com/mssql/server:2022-RTM-GDR1-ubuntu-20.04
2024/09/17 15:38:53 ✅ Container created: 06ded4ac3ae0
2024/09/17 15:38:53 🐳 Starting container: 06ded4ac3ae0
2024/09/17 15:38:54 ✅ Container started: 06ded4ac3ae0
2024/09/17 15:38:54 ⏳ Waiting for container id 06ded4ac3ae0 image: mcr.microsoft.com/mssql/server:2022-RTM-GDR1-ubuntu-20.04. Waiting for: &{timeout:<nil> Log:Recovery is complete. IsRegexp:false Occurrence:1 PollInterval:100ms}
2024/09/17 15:38:58 🔔 Container is ready: 06ded4ac3ae0
2024/09/17 15:39:00 🐳 Creating container for image mcr.microsoft.com/mssql/server:2022-RTM-GDR1-ubuntu-20.04
2024/09/17 15:39:00 ✅ Container created: 8e5288e9b2a6
2024/09/17 15:39:00 🐳 Starting container: 8e5288e9b2a6
2024/09/17 15:39:00 ✅ Container started: 8e5288e9b2a6
2024/09/17 15:39:00 ⏳ Waiting for container id 8e5288e9b2a6 image: mcr.microsoft.com/mssql/server:2022-RTM-GDR1-ubuntu-20.04. Waiting for: &{timeout:<nil> Log:Recovery is complete. IsRegexp:false Occurrence:1 PollInterval:100ms}
2024/09/17 15:39:05 🔔 Container is ready: 8e5288e9b2a6
2024/09/17 15:39:07 🐳 Creating container for image mcr.microsoft.com/mssql/server:2022-RTM-GDR1-ubuntu-20.04
2024/09/17 15:39:07 ✅ Container created: 63e2053a58eb
2024/09/17 15:39:07 🐳 Starting container: 63e2053a58eb
2024/09/17 15:39:07 ✅ Container started: 63e2053a58eb
2024/09/17 15:39:07 ⏳ Waiting for container id 63e2053a58eb image: mcr.microsoft.com/mssql/server:2022-RTM-GDR1-ubuntu-20.04. Waiting for: &{timeout:<nil> Log:Recovery is complete. IsRegexp:false Occurrence:1 PollInterval:100ms}
2024/09/17 15:39:12 🔔 Container is ready: 63e2053a58eb
Benchmark_MSSQL_Get-8                          6         191320208 ns/op          109934 B/op        601 allocs/op
Benchmark_MSSQL_SetAndDelete
2024/09/17 15:39:14 🐳 Creating container for image mcr.microsoft.com/mssql/server:2022-RTM-GDR1-ubuntu-20.04
2024/09/17 15:39:14 ✅ Container created: a17d4139d23b
2024/09/17 15:39:14 🐳 Starting container: a17d4139d23b
2024/09/17 15:39:14 ✅ Container started: a17d4139d23b
2024/09/17 15:39:14 ⏳ Waiting for container id a17d4139d23b image: mcr.microsoft.com/mssql/server:2022-RTM-GDR1-ubuntu-20.04. Waiting for: &{timeout:<nil> Log:Recovery is complete. IsRegexp:false Occurrence:1 PollInterval:100ms}
2024/09/17 15:39:19 🔔 Container is ready: a17d4139d23b
2024/09/17 15:39:20 🐳 Creating container for image mcr.microsoft.com/mssql/server:2022-RTM-GDR1-ubuntu-20.04
2024/09/17 15:39:20 ✅ Container created: a33e3ebb2c58
2024/09/17 15:39:20 🐳 Starting container: a33e3ebb2c58
2024/09/17 15:39:21 ✅ Container started: a33e3ebb2c58
2024/09/17 15:39:21 ⏳ Waiting for container id a33e3ebb2c58 image: mcr.microsoft.com/mssql/server:2022-RTM-GDR1-ubuntu-20.04. Waiting for: &{timeout:<nil> Log:Recovery is complete. IsRegexp:false Occurrence:1 PollInterval:100ms}
2024/09/17 15:39:25 🔔 Container is ready: a33e3ebb2c58
2024/09/17 15:39:27 🐳 Creating container for image mcr.microsoft.com/mssql/server:2022-RTM-GDR1-ubuntu-20.04
2024/09/17 15:39:27 ✅ Container created: d53d076a7b6c
2024/09/17 15:39:27 🐳 Starting container: d53d076a7b6c
2024/09/17 15:39:28 ✅ Container started: d53d076a7b6c
2024/09/17 15:39:28 ⏳ Waiting for container id d53d076a7b6c image: mcr.microsoft.com/mssql/server:2022-RTM-GDR1-ubuntu-20.04. Waiting for: &{timeout:<nil> Log:Recovery is complete. IsRegexp:false Occurrence:1 PollInterval:100ms}
2024/09/17 15:39:32 🔔 Container is ready: d53d076a7b6c
Benchmark_MSSQL_SetAndDelete-8                 3         412130153 ns/op          195160 B/op       1167 allocs/op
PASS
ok      github.com/gofiber/storage/mssql/v2     61.584s

Is there any way to relaunch the benchmark job, and try to identify where the flakiness is?

@ReneWerner87
Copy link
Member

I already restarted it 2 time

Pls test the workflow with act
https://github.com/nektos/act

@ReneWerner87
Copy link
Member

I restarted the benchmark action again with debug info
https://github.com/gofiber/storage/actions/runs/10886797247?pr=1515

The tests are failing because the container is terminated with error code 127
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: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between c80f126 and 4d7a172.

Files ignored due to path filters (8)
  • mongodb/go.mod is excluded by !**/*.mod
  • mongodb/go.sum is excluded by !**/*.sum, !**/*.sum
  • mssql/go.mod is excluded by !**/*.mod
  • mssql/go.sum is excluded by !**/*.sum, !**/*.sum
  • mysql/go.mod is excluded by !**/*.mod
  • mysql/go.sum is excluded by !**/*.sum, !**/*.sum
  • postgres/go.mod is excluded by !**/*.mod
  • postgres/go.sum is excluded by !**/*.sum, !**/*.sum
Files selected for processing (3)
  • .github/workflows/benchmark.yml (1 hunks)
  • .github/workflows/test-mssql.yml (2 hunks)
  • mssql/mssql_test.go (12 hunks)
Additional comments not posted (4)
.github/workflows/test-mssql.yml (2)

20-20: Go version update approved.

Adding Go version 1.22.x to the test matrix ensures compatibility with the latest Go release.


30-31: Environment variable TEST_MSSQL_IMAGE set appropriately.

Defining TEST_MSSQL_IMAGE with the specified image ensures consistency across testing environments.

.github/workflows/benchmark.yml (1)

115-118: Database image environment variables configured correctly.

The addition of TEST_MONGODB_IMAGE, TEST_MSSQL_IMAGE, TEST_MYSQL_IMAGE, and TEST_POSTGRES_IMAGE environment variables specifies the database images for testing, enhancing consistency and reproducibility.

mssql/mssql_test.go (1)

23-51: Well-implemented newTestStore function enhances test isolation.

The newTestStore function provides each test with an independent storage instance, improving test reliability and avoiding shared state.

Comment on lines 59 to 61
testStore, err := newTestStore(t)
require.NoError(t, err)

Copy link
Contributor

Choose a reason for hiding this comment

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

Ensure proper cleanup by closing the test store in tests and benchmarks.

In the test and benchmark functions, after initializing testStore, consider adding defer testStore.Close() to ensure that resources are properly released and to prevent potential resource leaks.

Apply the following diff to add the defer statements:

For tests:

 func Test_FunctionName(t *testing.T) {
 	testStore, err := newTestStore(t)
 	require.NoError(t, err)
+	defer testStore.Close()
 	// rest of the test code
 }

For benchmarks:

 func Benchmark_FunctionName(b *testing.B) {
 	testStore, err := newTestStore(b)
 	require.NoError(b, err)
+	defer testStore.Close()
 	// rest of the benchmark code
 }

Also applies to: 72-74, 88-90, 106-108, 118-120, 127-129, 141-143, 158-160, 182-184, 207-209, 234-236, 241-243, 248-250, 262-264, 279-281

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: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 4d7a172 and 1bb4d92.

Files selected for processing (7)
  • clickhouse/clickhouse_test.go (1 hunks)
  • couchbase/couchbase_test.go (10 hunks)
  • minio/minio_test.go (15 hunks)
  • mongodb/mongodb_test.go (11 hunks)
  • mssql/mssql_test.go (12 hunks)
  • mysql/mysql_test.go (13 hunks)
  • postgres/postgres_test.go (12 hunks)
Additional comments not posted (75)
couchbase/couchbase_test.go (11)

59-59: Good practice: Ensuring resource cleanup with defer testStore.Close()

Adding defer testStore.Close() ensures that the test store is properly closed after the test TestSetCouchbase_ShouldReturnNoError executes, preventing potential resource leaks.


69-69: Good practice: Ensuring resource cleanup in TestGetCouchbase_ShouldReturnNil_WhenDocumentNotFound

Including defer testStore.Close() guarantees that resources are released after the test, enhancing test reliability.


80-80: Good practice: Resource cleanup in TestSetAndGet_GetShouldReturn_SetValueWithoutError

The addition of defer testStore.Close() ensures that the test store is closed properly, preventing resource leaks.


94-94: Good practice: Proper resource management in TestSetAndGet_GetShouldReturnNil_WhenTTLExpired

Using defer testStore.Close() aids in cleaning up resources after the test execution.


110-110: Good practice: Ensuring resource cleanup in TestSetAndDelete_DeleteShouldReturn_NoError

Adding defer testStore.Close() ensures that the test store is properly closed, enhancing resource management.


125-125: Good practice: Resource cleanup in TestSetAndReset_ResetShouldReturn_NoError

Including defer testStore.Close() helps prevent resource leaks by ensuring the test store is closed after the test.


140-140: Good practice: Proper closure in TestClose_CloseShouldReturn_NoError

Adding defer testStore.Close() ensures that resources are released appropriately after the test execution.


149-149: Good practice: Ensuring resource cleanup in TestGetConn_ReturnsNotNil

Using defer testStore.Close() enhances resource management by closing the test store after the test.


157-157: Good practice: Resource cleanup in benchmark Benchmark_Couchbase_Set

Including defer testStore.Close() ensures that resources are properly released after the benchmark execution.


172-172: Good practice: Proper resource management in benchmark Benchmark_Couchbase_Get

Adding defer testStore.Close() helps prevent resource leaks during benchmark execution.


190-190: Good practice: Resource cleanup in benchmark Benchmark_Couchbase_SetAndDelete

Using defer testStore.Close() ensures that the test store is closed after the benchmark completes.

mongodb/mongodb_test.go (14)

21-44: Well-designed newTestStore function for test isolation

The newTestStore function effectively initializes a MongoDB test container using Testcontainers, enhancing test isolation and reliability by providing a fresh instance for each test.


53-56: Proper initialization and cleanup in Test_MongoDB_Set

Initializing the test store with newTestStore(t) and adding defer testStore.Close() ensures each test is isolated and that resources are properly released.


67-70: Consistent test setup in Test_MongoDB_Set_Override

Using the new test store initialization pattern enhances test reliability and resource management.


84-87: Improved resource management in Test_MongoDB_Get

Including defer testStore.Close() ensures that resources are cleaned up after the test execution.


103-106: Proper test isolation in Test_MongoDB_Set_Expiration

Initializing a fresh test store and deferring its closure helps prevent interference between tests.


116-119: Resource cleanup in Test_MongoDB_Get_Expired

Adding defer testStore.Close() ensures that the test store is properly closed after the test.


126-129: Consistent resource management in Test_MongoDB_Get_NotExist

Including defer testStore.Close() enhances resource cleanup post-test execution.


141-144: Proper closure of test store in Test_MongoDB_Delete

Using defer testStore.Close() ensures resources are released after the test runs.


159-162: Resource cleanup in Test_MongoDB_Reset

Adding defer testStore.Close() aids in preventing resource leaks.


182-185: Proper resource management in Test_MongoDB_Close

Deferring testStore.Close() ensures that resources are released appropriately.


190-193: Consistent cleanup in Test_MongoDB_Conn

Including defer testStore.Close() enhances resource management after the test execution.


198-201: Resource cleanup in benchmark Benchmark_MongoDB_Set

Adding defer testStore.Close() ensures that resources are properly released after the benchmark.


213-216: Proper resource management in benchmark Benchmark_MongoDB_Get

Using defer testStore.Close() helps prevent resource leaks during benchmark execution.


231-234: Resource cleanup in benchmark Benchmark_MongoDB_SetAndDelete

Including defer testStore.Close() ensures that the test store is closed after the benchmark completes.

clickhouse/clickhouse_test.go (1)

70-75: Proper assignment and resource cleanup in Test_Connection

Assigning the result of getTestConnection to client and deferring client.Close() ensures that the connection is utilized and properly closed after the test, preventing resource leaks.

minio/minio_test.go (15)

67-67: Good practice: Adding defer testStore.Close() in Test_Get

Including defer testStore.Close() ensures that resources are properly released after the test execution, preventing potential leaks.


88-88: Resource cleanup in Test_Get_Empty_Key

Adding defer testStore.Close() enhances resource management by closing the test store after the test.


102-102: Proper resource management in Test_Get_Not_Exists_Key

Using defer testStore.Close() ensures that resources are released appropriately after the test.


116-116: Consistent cleanup in Test_Get_Not_Exists_Bucket

Adding defer testStore.Close() helps prevent resource leaks by closing the test store.


135-135: Good practice: Ensuring resource cleanup in Test_Set

Including defer testStore.Close() ensures proper resource management.


149-149: Resource management in Test_Set_Empty_Key

Adding defer testStore.Close() ensures that resources are released after the test execution.


166-166: Proper closure in Test_Set_Not_Exists_Bucket

Using defer testStore.Close() enhances resource cleanup post-test.


184-184: Resource cleanup in Test_Delete

Including defer testStore.Close() ensures that the test store is properly closed after the test.


201-201: Consistent resource management in Test_Delete_Empty_Key

Adding defer testStore.Close() helps prevent resource leaks.


215-215: Proper resource cleanup in Test_Delete_Not_Exists_Bucket

Using defer testStore.Close() ensures resources are released appropriately.


233-233: Resource management in Test_Reset

Including defer testStore.Close() enhances test reliability by closing resources after execution.


252-252: Good practice: Ensuring resource cleanup in Test_Close

Adding defer testStore.Close() ensures that resources are properly released.


263-263: Resource cleanup in benchmark Benchmark_Minio_Set

Including defer testStore.Close() ensures proper resource management during benchmarks.


275-275: Proper resource management in benchmark Benchmark_Minio_Get

Adding defer testStore.Close() helps prevent resource leaks during benchmark execution.


293-293: Resource cleanup in benchmark Benchmark_Minio_SetAndDelete

Using defer testStore.Close() ensures that the test store is closed after the benchmark completes.

mssql/mssql_test.go (16)

23-51: Well-implemented newTestStore function for MSSQL test setup

The newTestStore function correctly initializes a MSSQL test container using Testcontainers, enhancing test isolation and ensuring each test operates with a fresh database instance.


59-62: Proper initialization and cleanup in Test_MSSQL_Set

Using newTestStore(t) and deferring testStore.Close() ensures tests are isolated and resources are properly managed.


73-76: Consistent test setup in Test_MSSQL_Set_Override

Adding defer testStore.Close() enhances resource management, consistent with previous test functions.


90-93: Resource cleanup in Test_MSSQL_Get

Including defer testStore.Close() ensures proper resource release after test execution.


109-112: Proper resource management in Test_MSSQL_Set_Expiration

Deferring testStore.Close() aids in resource cleanup.


122-125: Resource cleanup in Test_MSSQL_Get_Expired

Adding defer testStore.Close() ensures proper closure of the test store.


132-135: Consistent resource management in Test_MSSQL_Get_NotExist

Using defer testStore.Close() enhances test reliability.


147-150: Resource cleanup in Test_MSSQL_Delete

Including defer testStore.Close() ensures resources are released appropriately.


165-168: Proper resource management in Test_MSSQL_Reset

Deferring testStore.Close() aids in preventing resource leaks.


190-193: Resource cleanup in Test_MSSQL_GC

Adding defer testStore.Close() ensures resources are properly released after the test.


216-219: Proper closure in Test_MSSQL_Non_UTF8

Using defer testStore.Close() enhances resource management.


244-247: Resource cleanup in Test_MSSQL_Close

Including defer testStore.Close() ensures proper resource release.


252-255: Consistent resource management in Test_MSSQL_Conn

Adding defer testStore.Close() ensures resources are properly closed.


260-263: Resource cleanup in benchmark Benchmark_MSSQL_Set

Deferring testStore.Close() prevents resource leaks during benchmark execution.


275-278: Proper resource management in benchmark Benchmark_MSSQL_Get

Using defer testStore.Close() ensures resources are released after the benchmark.


293-296: Resource cleanup in benchmark Benchmark_MSSQL_SetAndDelete

Including defer testStore.Close() helps prevent resource leaks in benchmarks.

mysql/mysql_test.go (18)

23-39: Well-structured newTestStore function for MySQL test setup

The newTestStore function effectively initializes a MySQL test container using Testcontainers, improving test isolation by providing a fresh database instance for each test.


41-57: Proper container management in mustStartMySQL function

The mustStartMySQL function correctly starts a MySQL container with specified configurations, enhancing the reliability of the testing environment.


59-70: Improved test initialization in Test_MYSQL_New

Initializing the test store using the new pattern and handling errors appropriately enhances test reliability.


88-91: Proper resource management in Test_MYSQL_Set

Using newTestStore(t) and deferring testStore.Close() ensures resources are managed correctly.


102-105: Consistent test setup in Test_MYSQL_Set_Override

Including defer testStore.Close() aids in resource cleanup after the test execution.


119-122: Resource cleanup in Test_MYSQL_Get

Adding defer testStore.Close() ensures that the test store is properly closed.


138-141: Proper resource management in Test_MYSQL_Set_Expiration

Deferring testStore.Close() helps in resource cleanup post-test execution.


151-154: Resource cleanup in Test_MYSQL_Get_Expired

Including defer testStore.Close() ensures resources are properly released.


161-164: Consistent resource management in Test_MYSQL_Get_NotExist

Adding defer testStore.Close() enhances resource cleanup.


176-179: Proper resource management in Test_MYSQL_Delete

Using defer testStore.Close() ensures the test store is closed after the test.


194-197: Resource cleanup in Test_MYSQL_Reset

Deferring testStore.Close() aids in preventing resource leaks.


220-223: Resource management in Test_MYSQL_GC

Including defer testStore.Close() ensures resources are released appropriately after the test.


245-248: Proper closure in Test_MYSQL_Non_UTF8

Using defer testStore.Close() ensures proper resource cleanup.


258-261: Resource cleanup in Test_MYSQL_Close

Adding defer testStore.Close() enhances resource management post-test execution.


266-269: Consistent resource management in Test_MYSQL_Conn

Deferring testStore.Close() ensures that resources are properly released.


274-277: Resource cleanup in benchmark Benchmark_MYSQL_Set

Using defer testStore.Close() helps prevent resource leaks during benchmark execution.


289-292: Proper resource management in benchmark Benchmark_MYSQL_Get

Including defer testStore.Close() ensures resources are released after the benchmark.


307-310: Resource cleanup in benchmark Benchmark_MYSQL_SetAndDelete

Adding defer testStore.Close() ensures the test store is closed after the benchmark completes.

Comment on lines 25 to 56
func newTestStore(t testing.TB) (*Storage, error) {
t.Helper()

ctx := context.Background()

img := postgresImage
if imgFromEnv := os.Getenv(postgresImageEnvVar); imgFromEnv != "" {
img = imgFromEnv
}

c, err := postgres.Run(ctx, img,
postgres.WithUsername(postgresUser),
postgres.WithPassword(postgresPass),
postgres.WithDatabase(postgresDatabase),
testcontainers.WithWaitStrategy(
// First, we wait for the container to log readiness twice.
// This is because it will restart itself after the first startup.
wait.ForLog("database system is ready to accept connections").WithOccurrence(2),
),
)
require.NoError(t, err)

conn, err := c.ConnectionString(ctx, "sslmode=disable")
if err != nil {
return nil, err
}

return New(Config{
ConnectionURI: conn,
Reset: true,
}), nil
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Ensure proper cleanup of test containers to prevent resource leaks

The newTestStore function creates a new PostgreSQL container for each test but does not terminate the container after the test completes. This could lead to resource leaks and accumulation of unused Docker containers during testing.

Apply this diff to ensure the container is properly terminated:

 func newTestStore(t testing.TB) (*Storage, error) {
     t.Helper()

     ctx := context.Background()

     img := postgresImage
     if imgFromEnv := os.Getenv(postgresImageEnvVar); imgFromEnv != "" {
         img = imgFromEnv
     }

     c, err := postgres.Run(ctx, img,
         postgres.WithUsername(postgresUser),
         postgres.WithPassword(postgresPass),
         postgres.WithDatabase(postgresDatabase),
         testcontainers.WithWaitStrategy(
             // First, we wait for the container to log readiness twice.
             // This is because it will restart itself after the first startup.
             wait.ForLog("database system is ready to accept connections").WithOccurrence(2),
         ),
     )
     require.NoError(t, err)

     conn, err := c.ConnectionString(ctx, "sslmode=disable")
     if err != nil {
         return nil, err
     }

-    return New(Config{
+    store := New(Config{
         ConnectionURI: conn,
         Reset:         true,
-    }), nil
+    })

+    cleanup := func() {
+        err := c.Terminate(ctx)
+        require.NoError(t, err)
+    }

-    return store, nil
+    return store, cleanup, nil
 }

Then, update your test functions to handle the cleanup function:

-func Test_Postgres_Set(t *testing.T) {
+func Test_Postgres_Set(t *testing.T) {
     var (
         key = "john"
         val = []byte("doe")
     )

-    testStore, err := newTestStore(t)
+    testStore, cleanup, err := newTestStore(t)
     require.NoError(t, err)
     defer testStore.Close()
+    defer cleanup()

     err = testStore.Set(key, val, 0)
     require.NoError(t, err)
 }

Repeat this change for all other test functions using newTestStore.

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
func newTestStore(t testing.TB) (*Storage, error) {
t.Helper()
ctx := context.Background()
img := postgresImage
if imgFromEnv := os.Getenv(postgresImageEnvVar); imgFromEnv != "" {
img = imgFromEnv
}
c, err := postgres.Run(ctx, img,
postgres.WithUsername(postgresUser),
postgres.WithPassword(postgresPass),
postgres.WithDatabase(postgresDatabase),
testcontainers.WithWaitStrategy(
// First, we wait for the container to log readiness twice.
// This is because it will restart itself after the first startup.
wait.ForLog("database system is ready to accept connections").WithOccurrence(2),
),
)
require.NoError(t, err)
conn, err := c.ConnectionString(ctx, "sslmode=disable")
if err != nil {
return nil, err
}
return New(Config{
ConnectionURI: conn,
Reset: true,
}), nil
}
func newTestStore(t testing.TB) (*Storage, func(), error) {
t.Helper()
ctx := context.Background()
img := postgresImage
if imgFromEnv := os.Getenv(postgresImageEnvVar); imgFromEnv != "" {
img = imgFromEnv
}
c, err := postgres.Run(ctx, img,
postgres.WithUsername(postgresUser),
postgres.WithPassword(postgresPass),
postgres.WithDatabase(postgresDatabase),
testcontainers.WithWaitStrategy(
// First, we wait for the container to log readiness twice.
// This is because it will restart itself after the first startup.
wait.ForLog("database system is ready to accept connections").WithOccurrence(2),
),
)
require.NoError(t, err)
conn, err := c.ConnectionString(ctx, "sslmode=disable")
if err != nil {
return nil, nil, err
}
store := New(Config{
ConnectionURI: conn,
Reset: true,
})
cleanup := func() {
err := c.Terminate(ctx)
require.NoError(t, err)
}
return store, cleanup, nil
}

This is not relevant for this PR, as Ryuk is responsible for terminating containers after the test session finishes
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: 2

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 1bb4d92 and f962d64.

Files selected for processing (7)
  • clickhouse/clickhouse_test.go (2 hunks)
  • couchbase/couchbase_test.go (11 hunks)
  • minio/minio_test.go (16 hunks)
  • mongodb/mongodb_test.go (11 hunks)
  • mssql/mssql_test.go (12 hunks)
  • mysql/mysql_test.go (13 hunks)
  • postgres/postgres_test.go (12 hunks)
Files skipped from review due to trivial changes (1)
  • minio/minio_test.go
Files skipped from review as they are similar to previous changes (3)
  • clickhouse/clickhouse_test.go
  • couchbase/couchbase_test.go
  • mssql/mssql_test.go
Additional comments not posted (2)
mongodb/mongodb_test.go (1)

21-51: Great job on enhancing test isolation with newTestStore!

The newTestStore function effectively encapsulates the setup and teardown of the MongoDB test store using Testcontainers. The use of t.Cleanup ensures proper resource cleanup, preventing resource leaks. This change improves test reliability and maintains clean test environments.

postgres/postgres_test.go (1)

35-50: Excellent resource cleanup with t.Cleanup

The implementation of t.Cleanup to terminate the PostgreSQL container ensures that resources are properly cleaned up after tests, preventing potential resource leaks.

Comment on lines 18 to 19
mysqlUser string = "password"
mysqlPass string = "username"
Copy link
Contributor

Choose a reason for hiding this comment

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

Swap mysqlUser and mysqlPass values to correct credentials

The constants for mysqlUser and mysqlPass appear to be swapped. Currently, mysqlUser is set to "password" and mysqlPass is set to "username", which is likely unintended.

Apply this diff to correct the username and password assignments:

 const (
     // mysqlImage is the default image used for running MySQL in tests.
     mysqlImage              = "docker.io/mysql:9"
     mysqlImageEnvVar string = "TEST_MYSQL_IMAGE"
-    mysqlUser        string = "password"
-    mysqlPass        string = "username"
+    mysqlUser        string = "username"
+    mysqlPass        string = "password"
     mysqlDatabase    string = "fiber"
 )
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
mysqlUser string = "password"
mysqlPass string = "username"
mysqlUser string = "username"
mysqlPass string = "password"

Comment on lines +49 to +53
c, err := mysql.Run(ctx, img,
mysql.WithPassword(mysqlPass),
mysql.WithUsername(mysqlUser),
mysql.WithDatabase(mysqlDatabase),
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Tip

Codebase Verification

Swap mysqlUser and mysqlPass constant definitions

The mysql.Run function call in mustStartMySQL is correct, using mysqlUser with WithUsername and mysqlPass with WithPassword. However, the constant definitions are incorrect:

  • mysqlUser is defined as "password"
  • mysqlPass is defined as "username"

These definitions should be swapped to correctly represent their intended values.

Analysis chain

Verify MySQL container credentials in mustStartMySQL

Ensure that the credentials passed to mysql.Run match the corrected mysqlUser and mysqlPass constants after swapping them.

Run the following script to confirm that the username and password are correctly used:

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that the username and password in mustStartMySQL match the constants.

# Expected result: The literals "mysqlUser" and "mysqlPass" should be used with the correct methods.

ast-grep --lang go --pattern $'mysql.Run($_, $_,\n    mysql.WithUsername(mysqlUser),\n    mysql.WithPassword(mysqlPass),\n    $$$\n)'

Length of output: 130


Script:

#!/bin/bash
# Display the content of mysql/mysql_test.go
cat mysql/mysql_test.go

# Search for mysqlUser and mysqlPass constants
rg "mysqlUser|mysqlPass" mysql/mysql_test.go

# Find mysql.Run function call with a more flexible pattern
ast-grep --lang go --pattern 'mysql.Run($_, $_, $$$)'

Length of output: 6894

@mdelapenya
Copy link
Contributor Author

@ReneWerner87 I noticed a regression in the recent update (Azure DevOps agent / GitHub Actions runner): actions/runner-images#10649

I think it could be related 🤔

@mdelapenya
Copy link
Contributor Author

@ReneWerner87 I resolved the MSSQL errors caused by the recent GH workers upgrade, and I'm currently debugging the couchbase failures (https://github.com/gofiber/storage/actions/runs/10950265038/job/30405176292?pr=1515) where it only fails for Go 1.20 🤷 Do you think it could be caused by the number of running containers so the worker could eventually be non-responsive? I'd say that the same happens for the benchmarks. Will update this thread after my research.

Sorry for the inconvenience 🙏

@ReneWerner87
Copy link
Member

Do you think it could be caused by the number of running containers

could be possible

thanks for the effort so far

@gaby
Copy link
Member

gaby commented Sep 20, 2024

@mdelapenya Did you add "wait_for" to each service? A lot of these services take a bit to start, so it could be that.

@mdelapenya
Copy link
Contributor Author

@mdelapenya Did you add "wait_for" to each service? A lot of these services take a bit to start, so it could be that.

Indeed, we always recommend adding wait strategies for container, so our modules usually come with a wait strategy.

For couchbase we have this: https://github.com/testcontainers/testcontainers-go/blob/main/modules/couchbase/couchbase.go#L189

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