Skip to content

Conversation

@mkysel
Copy link
Collaborator

@mkysel mkysel commented Jun 3, 2025

Introduce XDBG integration tests by renaming upgrade test package to integration and adding XDBG container testing functionality

The upgrade test package has been renamed to integration and expanded with XDBG testing capabilities:
• Renamed GitHub workflow from upgrade-test.yml to integration-test.yml with updated job names and environment variables
• Moved all test files from pkg/upgrade/ to pkg/integration/ with package name changes from upgrade_test to integration_test
• Modified runContainer function in docker_utils_test.go to return container instance and added XDBG container support with GeneratorType enum and runXDBG function
• Added new xdbg_test.go test that runs XDBG with identity, group, and message generator types against xmtpd container
• Updated test environment to enable XMTPD_PAYER_ENABLE and use XDBG image ghcr.io/xmtp/xdbg:sha-78a5ac2

📍Where to Start

Start with the new XDBG test in xdbg_test.go to understand the main integration testing functionality, then review the runXDBG function in docker_utils_test.go.


Macroscope summarized a026122.

Summary by CodeRabbit

  • New Features

    • Added new integration tests for container upgrades and latest version validation.
    • Introduced utilities for managing Docker containers and networks in integration tests.
    • Added a test verifying container functionality with multiple generator types and payloads.
  • Refactor

    • Renamed environment variables and test packages from "upgrade" to "integration" for improved clarity.
  • Chores

    • Updated GitHub Actions workflow to reflect the new integration test naming and environment variables.

@mkysel mkysel requested a review from a team as a code owner June 3, 2025 15:54
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 3, 2025

Walkthrough

The changes transition the integration test suite from "Upgrade Tests" to "Integration Tests" across workflow files and test code. A new utility for managing Docker containers and networks is introduced, including specialized builders for xmtpd and xdbg containers. A new integration test exercises the xdbg container with multiple generator types. Test utility functions improve container lifecycle management and error handling.

Changes

Files/Groups Change Summary
.github/workflows/integration-test.yml Renamed job and steps from "Upgrade Tests" to "Integration Tests"; updated environment variable and test package path.
pkg/integration/docker_utils_test.go Added new file with Docker container and network utilities; introduced XmtpdContainerBuilder, XdbgContainerBuilder, and related helpers.
pkg/integration/main_test.go Changed package name from upgrade_test to integration_test; updated setup log message accordingly.
pkg/integration/upgrade_test.go Added new test file with upgrade-related tests using container builders to test old and latest images.
pkg/integration/xdbg_test.go Added new integration test TestXDBGRealMLSPayloads that runs xdbg containers with different generator types against an xmtpd container.

Sequence Diagram(s)

sequenceDiagram
    participant Test as TestXDBGRealMLSPayloads
    participant Docker as Docker Engine
    participant XMTDP as xmtpd Container
    participant XDBG as xdbg Container

    Test->>Docker: Start xmtpd container (ghcr.io/xmtp/xmtpd:dev)
    Docker-->>Test: Container started, port mapped
    loop For each GeneratorType (identity, group, message)
        Test->>Docker: Start xdbg container with GeneratorType and count=10
        Docker->>XDBG: Run container, wait for exit
        XDBG-->>Docker: Exit (success or failure)
        Docker-->>Test: Return exit status, logs if failure
    end
    Test-->>Test: Assert no errors for all steps
Loading

Possibly related PRs

  • Add from-0.3.0 upgrade tests #710: Adds new integration test infrastructure and upgrade tests using xmtpdVersions in upgrade_test.go, directly related to upgrade test functionality introduced here.

Suggested reviewers

  • fbac

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (1.64.8)

Error: you are using a configuration file for golangci-lint v2 with golangci-lint v1: please use golangci-lint v2
Failed executing command with error: you are using a configuration file for golangci-lint v2 with golangci-lint v1: please use golangci-lint v2

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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 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.

@graphite-app
Copy link

graphite-app bot commented Jun 3, 2025

How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • Queue - adds this PR to the back of the merge queue
  • Hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

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

🧹 Nitpick comments (3)
pkg/integration/upgrade_test.go (1)

1-1: Consider utilizing the returned container instances.

The updates correctly match the new runContainer signature. However, the returned container instances could be used for additional assertions or debugging.

You could enhance the tests by checking container health or logs:

-			_, err := runContainer(
+			container, err := runContainer(
 				t,
 				image,
 				fmt.Sprintf("xmtpd_test_%s", version),
 				envVars,
 			)
 			require.NoError(t, err, "Failed to start container version %s", version)
+			
+			// Optional: Verify container is healthy
+			state, stateErr := container.State(t.Context())
+			require.NoError(t, stateErr)
+			require.True(t, state.Running, "Container should be running")

Also applies to: 24-29, 33-39, 46-52

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

1-1: Update the workflow name to match the job renaming.

The workflow name still references "Upgrade Tests" but should be updated to "Integration Tests" to be consistent with the job name change on line 11.

-name: Upgrade Tests
+name: Integration Tests
pkg/integration/xdbg_test.go (1)

23-28: Consider enhancing test validation.

The test only verifies that XDBG runs without errors but doesn't validate the actual functionality or outputs. Consider adding assertions to verify that the XDBG operations actually performed their intended actions.

For example, you could:

  • Verify that the expected number of entities were generated
  • Check container logs for success messages
  • Validate that the XDBG container completed successfully
// Example enhancement:
logs, err := container.Logs(context.Background())
require.NoError(t, err)
// Add assertions on log content to verify successful operations
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f8358a1 and a026122.

📒 Files selected for processing (5)
  • .github/workflows/integration-test.yml (2 hunks)
  • pkg/integration/docker_utils_test.go (6 hunks)
  • pkg/integration/main_test.go (2 hunks)
  • pkg/integration/upgrade_test.go (3 hunks)
  • pkg/integration/xdbg_test.go (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
pkg/integration/xdbg_test.go (1)
pkg/integration/docker_utils_test.go (3)
  • GeneratorTypeIdentity (195-195)
  • GeneratorTypeGroup (196-196)
  • GeneratorTypeMessage (197-197)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Test (Node)
  • GitHub Check: Integration Tests
🔇 Additional comments (9)
pkg/integration/docker_utils_test.go (5)

1-1: LGTM! Package rename and imports are appropriate.

The package rename to integration_test aligns with the PR objective, and the new imports are properly utilized by the new XDBG integration functionality.

Also applies to: 13-13, 18-19


73-73: LGTM! Enabling payer component for integration tests.

The addition of XMTPD_PAYER_ENABLE is consistent with enabling other components for comprehensive integration testing.


147-190: Excellent refactoring of the runContainer function!

The changes improve the function in several ways:

  • Using t.Context() is more idiomatic for test functions
  • Returning the container instance gives callers better control over container lifecycle
  • The timeout is preserved through the context

192-202: Well-structured type definition for generator types.

Good use of typed string constants for compile-time safety. The String() method implementation is clean and follows Go conventions.


247-275: Excellent error handling implementation!

The function provides comprehensive error handling with:

  • Clear error messages including exit codes
  • Container logs included in error output for debugging
  • Graceful handling of log retrieval failures
  • Proper resource cleanup
pkg/integration/main_test.go (1)

1-1: LGTM! Consistent naming updates.

The package rename and setup message update are consistent with the transition from "Upgrade Tests" to "Integration Tests".

Also applies to: 12-12

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

11-11: LGTM! Consistent renaming from upgrade to integration tests.

The changes properly rename the test suite from "Upgrade Tests" to "Integration Tests" with appropriate updates to:

  • Job name
  • Step name
  • Environment variable
  • Test package path

Also applies to: 32-32, 36-37

pkg/integration/xdbg_test.go (2)

9-29: Well-structured integration test with comprehensive generator coverage.

The test effectively covers all three generator types (Identity, Group, Message) and uses proper error handling. The approach of testing against a real container provides good integration coverage.


20-21:

Details

✅ Verification successful

Verify the context usage.

The t.Context() method usage needs verification as it's not a standard testing.T method.


🏁 Script executed:

#!/bin/bash
# Description: Check if t.Context() is from a custom testing framework or extension
# Expected: Find the source of this method, likely from testcontainers or a custom extension

# Search for Context method definitions in test utilities
ast-grep --pattern 'func ($_ *testing.T) Context() $$$'

# Search for any Context method usage in test files
rg "\.Context\(\)" --type go -A 2 -B 2

# Look for imports that might extend testing.T
rg "testcontainers" --type go -A 5 -B 5

Length of output: 24755


Confirm standard testing.T.Context usage

The Context() method on *testing.T is provided by the Go standard library (since Go 1.17) and there’s no custom implementation in our codebase. Using t.Context() here is correct—no additional imports or extensions are required.

@macroscopeapp
Copy link

macroscopeapp bot commented Jun 3, 2025

Introduce XDBG integration tests by migrating upgrade tests to integration package and adding XDBG container testing capabilities

The upgrade testing package is renamed to integration testing package and expanded with XDBG testing capabilities. The changes include:
• Migration of existing upgrade tests from pkg/upgrade to pkg/integration package with updated container builder patterns
• Addition of XDBG integration tests in xdbg_test.go that verify XMTPD handling of generated identities, groups, and messages
• Introduction of Docker container builder patterns for both XMTPD and XDBG containers in docker_utils_test.go
• Update of GitHub workflow from upgrade-test.yml to run integration tests instead of upgrade tests
• Addition of Docker network creation utilities and GeneratorType enums for different test data types

📍Where to Start

Start with the new XDBG integration test in xdbg_test.go to understand the main testing functionality, then review the container builder patterns in docker_utils_test.go.


Macroscope summarized 63856c3.

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

🧹 Nitpick comments (2)
pkg/integration/upgrade_test.go (1)

23-26: Consider testing container functionality beyond startup.

While the current test verifies that containers start successfully, it doesn't validate that the upgrade actually preserves functionality or data integrity. Consider adding basic functionality checks after container startup.

 t.Logf("Starting old container")
-, err := NewXmtpdContainerBuilder(t).
+oldContainer, err := NewXmtpdContainerBuilder(t).
     WithImage(image).
     Build(t)
 require.NoError(t, err)
+
+// Add basic functionality check here
+// e.g., health check, API endpoint verification
pkg/integration/docker_utils_test.go (1)

246-272: Consider making timeout configurable.

The 10-second timeout for container startup might be too short for some environments or slower systems. Consider making this configurable or increasing the default.

 func (b *XmtpdContainerBuilder) Build(t *testing.T) (testcontainers.Container, error) {
-    ctx, cancel := context.WithTimeout(t.Context(), 10*time.Second)
+    timeout := 30*time.Second
+    if envTimeout := os.Getenv("CONTAINER_START_TIMEOUT"); envTimeout != "" {
+        if d, err := time.ParseDuration(envTimeout); err == nil {
+            timeout = d
+        }
+    }
+    ctx, cancel := context.WithTimeout(t.Context(), timeout)
     defer cancel()
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ef15680 and 16b0c31.

📒 Files selected for processing (3)
  • pkg/integration/docker_utils_test.go (1 hunks)
  • pkg/integration/upgrade_test.go (1 hunks)
  • pkg/integration/xdbg_test.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • pkg/integration/xdbg_test.go
🧰 Additional context used
🧠 Learnings (1)
pkg/integration/docker_utils_test.go (1)
Learnt from: mkysel
PR: xmtp/xmtpd#865
File: pkg/integration/docker_utils_test.go:30-33
Timestamp: 2025-06-03T16:14:31.420Z
Learning: The XDBG image reference `ghcr.io/xmtp/xdbg:sha-78a5ac2` is a valid and existing image in the GitHub Container Registry for XMTP integration tests.
🧬 Code Graph Analysis (1)
pkg/integration/upgrade_test.go (1)
pkg/integration/docker_utils_test.go (1)
  • NewXmtpdContainerBuilder (200-212)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: Integration Tests
  • GitHub Check: Test (Node)
  • GitHub Check: Push Docker Images to GitHub Packages (xmtpd-cli)
  • GitHub Check: Push Docker Images to GitHub Packages (xmtpd)
🔇 Additional comments (8)
pkg/integration/upgrade_test.go (1)

11-12: Empty version slice makes upgrade test ineffective.

The xmtpdVersions slice is currently empty, which means TestUpgradeToLatest will not execute any test iterations. This renders the upgrade testing functionality non-operational.

Please populate this slice with actual version tags that should be tested for upgrade compatibility, or consider adding a TODO comment if versions will be added later.

pkg/integration/docker_utils_test.go (7)

30-34: Constants are well-defined and consistent.

The constants are appropriately named and the XDBG image reference has been confirmed as valid. The naming follows Go conventions.


71-79: Environment variable configuration looks comprehensive.

The function properly enables required services and generates unique database names for test isolation. The use of caller name and random string ensures test independence.


98-122: Build function has proper timeout and error handling.

The Docker image building function includes appropriate timeout handling and distinguishes between timeout and other execution errors. The 5-minute timeout is reasonable for container builds.


160-189: Excellent error handling for container exit status.

The handleExitedContainer function provides comprehensive error reporting by checking exit codes and including container logs when failures occur. This will be invaluable for debugging test failures.


200-212: XmtpdContainerBuilder initialization is well-structured.

The builder pattern implementation is clean and the default configuration with anvil.json is appropriate for integration testing. The file mounting setup follows testcontainers best practices.


312-351: XdbgContainerBuilder implementation addresses previous concerns.

The error handling for os.MkdirAll has been properly implemented (lines 316-318), addressing the previous review feedback. The container configuration and volume mounting are correctly structured.


353-357: Network utility function is concise and effective.

The MakeDockerNetwork function provides a clean abstraction for creating test networks with proper error handling.

@mkysel mkysel force-pushed the mkysel/xdbg-test branch from 16b0c31 to 07f64ef Compare June 5, 2025 16:00
@mkysel mkysel merged commit 0e31277 into main Jun 5, 2025
9 checks passed
@mkysel mkysel deleted the mkysel/xdbg-test branch June 5, 2025 16:30
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