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

Add some basic integration tests #100

Merged
merged 1 commit into from
Nov 7, 2024

Conversation

lawrence-forooghian
Copy link
Collaborator

@lawrence-forooghian lawrence-forooghian commented Nov 7, 2024

It’s unlikely that we’re going to have a working unified test suite before the beta release, so here are some very basic smoke tests just to give us a little bit of confidence that things are kind of working and that we don’t introduce major regressions.

Would be good to have a way of separating these from the unit tests so that they don’t slow them down, but can figure that out later; I don’t have loads of time to spend on this at the moment.

Summary by CodeRabbit

Release Notes

  • New Features

    • Added a new submodule for enhanced testing capabilities.
    • Introduced a Sandbox enum for creating API keys in the Ably sandbox environment.
    • Implemented basic integration tests for the AblyChat functionality to ensure proper message handling.
  • Documentation

    • Updated CONTRIBUTING.md with new setup instructions and testing guidelines.
    • Modified .prettierignore to exclude specific test directories from formatting.
  • Chores

    • Enhanced GitHub Actions workflow to include submodule checkouts for improved build processes.

Copy link

coderabbitai bot commented Nov 7, 2024

Walkthrough

The changes in this pull request primarily involve updates to the GitHub Actions workflow to include submodule support, the addition of a new submodule in the .gitmodules file, and modifications to the CONTRIBUTING.md file to enhance setup instructions and testing guidelines. Additionally, new files for integration testing and sandbox API key creation were introduced, along with updates to the Package.swift file to include resources for testing. These changes collectively improve the project's structure and testing capabilities.

Changes

File Change Summary
.github/workflows/check.yaml Added with: submodules: true to actions/checkout@v4 in multiple jobs to ensure Git submodules are checked out.
.gitmodules Added submodule ably-common located at Tests/AblyChatTests/ably-common with URL https://github.com/ably/ably-common.
.prettierignore Added entry to ignore Tests/AblyChatTests/ably-common directory from Prettier formatting.
CONTRIBUTING.md Updated setup instructions to include git submodule update --init as the first command; added guidelines for testing new features and naming conventions for APIs.
Package.swift Added a resources section in the AblyChatTests test target to include the ably-common directory.
Tests/AblyChatTests/Helpers/Sandbox.swift Introduced Sandbox enum with methods for creating an API key and loading request body, along with an error handling enum.
Tests/AblyChatTests/IntegrationTests.swift Created integration tests for AblyChat functionality, including methods for creating sandbox clients and validating message sending and receiving.
Tests/AblyChatTests/ably-common Introduced a new subproject commit with hash 60fd9cf106abb1d6292fdd87d63ea33c552c8f33.

Possibly related PRs

  • [ECO-4980] Add a script to show spec coverage #93: Modifies the .github/workflows/check.yaml file to add a job related to spec coverage, aligning with the main PR's focus on enhancing the checkout process for submodules.
  • [ECO-4990] Switch to Swift Testing #61: Involves a transition to a new testing framework, which may indirectly relate to the changes in the main PR that improve the workflow for handling submodules, as both aim to enhance the development and testing processes within the repository.

Suggested reviewers

  • maratal
  • umair-ably

Poem

🐇 In the meadow, we hop with glee,
New submodules join, as happy as can be!
With tests that run and features bright,
Our code now dances, a joyful sight!
So let’s create keys and chat away,
In our sandbox world, we’ll play all day! 🌼


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 6f69d1d and 1c2bf47.

📒 Files selected for processing (8)
  • .github/workflows/check.yaml (6 hunks)
  • .gitmodules (1 hunks)
  • .prettierignore (1 hunks)
  • CONTRIBUTING.md (2 hunks)
  • Package.swift (1 hunks)
  • Tests/AblyChatTests/Helpers/Sandbox.swift (1 hunks)
  • Tests/AblyChatTests/IntegrationTests.swift (1 hunks)
  • Tests/AblyChatTests/ably-common (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (8)
  • .github/workflows/check.yaml
  • .gitmodules
  • .prettierignore
  • CONTRIBUTING.md
  • Package.swift
  • Tests/AblyChatTests/Helpers/Sandbox.swift
  • Tests/AblyChatTests/IntegrationTests.swift
  • Tests/AblyChatTests/ably-common

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 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.

@lawrence-forooghian lawrence-forooghian force-pushed the fix-Message-createdAt-decoding branch from 77456aa to 99136ef Compare November 7, 2024 02:19
@lawrence-forooghian lawrence-forooghian marked this pull request as ready for review November 7, 2024 02:20
@lawrence-forooghian lawrence-forooghian force-pushed the fix-Message-createdAt-decoding branch from 99136ef to 9454e40 Compare November 7, 2024 02:31
@lawrence-forooghian lawrence-forooghian force-pushed the basic-integration-tests branch 3 times, most recently from 2681b87 to 67d4145 Compare November 7, 2024 02:45
Copy link

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

🧹 Outside diff range and nitpick comments (6)
Tests/AblyChatTests/IntegrationTests.swift (2)

5-9: Consider increasing the time limit and adding setup documentation.

While one minute might be sufficient for basic tests, integration tests can be sensitive to network conditions and API response times. Additionally, the documentation could be enhanced to include:

  • Prerequisites (e.g., sandbox environment setup)
  • Test data requirements
  • Expected network conditions
 @Suite(
-    .timeLimit(.minutes(1))
+    .timeLimit(.minutes(2))
 )
-/// Some very basic integration tests, just to check that things are kind of working.
+/// Integration tests validating core chat functionality:
+/// - Message sending and receiving
+/// - Historical message retrieval
+/// - Room attachment/detachment
+///
+/// Prerequisites:
+/// - Sandbox environment access
+/// - Network connectivity
+/// Note: Tests may take longer under slow network conditions
 struct IntegrationTests {

1-58: Consider test organization strategies.

As mentioned in the PR objectives, separating integration tests from unit tests would be beneficial. Consider these approaches:

  1. Use test tags to filter integration tests:
@Suite("integration")
  1. Move integration tests to a separate target in Package.swift:
.testTarget(
    name: "AblyChatIntegrationTests",
    dependencies: ["AblyChat"]
)

This would allow running integration tests separately using:

swift test --filter AblyChatIntegrationTests
CONTRIBUTING.md (2)

11-13: Consider documenting the purpose of the submodule.

While the setup instructions are clear, it would be helpful to briefly explain what the submodule contains and why it's necessary for development. This context would help new contributors understand the project structure better.

-1. `git submodule update --init`
+1. `git submodule update --init` # Initialize the ably-common submodule containing shared test utilities

29-29: Enhance integration testing guidelines.

While the guideline to add integration tests is good, consider expanding it to include:

  1. What constitutes "core functionality" that should be smoke tested
  2. Best practices for writing integration tests
  3. Guidelines for managing test execution time (as mentioned in PR objectives about separating integration tests from unit tests)

Example addition:

-If you add a new feature, try to extend the `IntegrationTests` tests to perform a smoke test of its core functionality.
+If you add a new feature, try to extend the `IntegrationTests` tests to perform a smoke test of its core functionality. Core functionality typically includes:
+- Basic happy path scenarios
+- Critical error cases
+- Integration points with Ably's core services
+
+To manage test execution time:
+- Keep integration tests focused on end-to-end workflows
+- Use unit tests for detailed edge cases
+- Tag tests with `@IntegrationTest` to allow separate execution
Tests/AblyChatTests/Helpers/Sandbox.swift (2)

31-31: Avoid force unwrapping URL strings

Force unwrapping the result of URL(string:) can lead to a crash if the URL is invalid. Even though the URL is hardcoded, it's good practice to handle it safely.

Apply this diff:

-        var request = URLRequest(url: .init(string: "https://sandbox-rest.ably.io/apps")!)
+        guard let url = URL(string: "https://sandbox-rest.ably.io/apps") else {
+            throw Error.invalidURL
+        }
+        var request = URLRequest(url: url)

Add to your Error enum:

case invalidURL

17-29: Consider refactoring loadAppCreationRequestBody() to improve readability and efficiency

The current implementation involves reading a JSON file, deserializing it into a dictionary, extracting a subcomponent, and then serializing it back to Data. This can be streamlined by decoding directly into a Codable struct.

Here's how you might refactor the method:

private struct AppSetup: Codable {
    var post_apps: [PostApp]
}

private struct PostApp: Codable {
    // Define the properties as per your JSON structure
}

private static func loadAppCreationRequestBody() throws -> Data {
    guard let testAppSetupFileURL = Bundle.module.url(
        forResource: "test-app-setup",
        withExtension: "json",
        subdirectory: "ably-common/test-resources"
    ) else {
        throw Error.resourceNotFound("test-app-setup.json")
    }

    let data = try Data(contentsOf: testAppSetupFileURL)
    let appSetup = try JSONDecoder().decode(AppSetup.self, from: data)
    return try JSONEncoder().encode(appSetup.post_apps)
}

This approach eliminates the need for force casting and makes the code more type-safe.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 9454e40 and 67d4145.

📒 Files selected for processing (8)
  • .github/workflows/check.yaml (6 hunks)
  • .gitmodules (1 hunks)
  • .prettierignore (1 hunks)
  • CONTRIBUTING.md (2 hunks)
  • Package.swift (1 hunks)
  • Tests/AblyChatTests/Helpers/Sandbox.swift (1 hunks)
  • Tests/AblyChatTests/IntegrationTests.swift (1 hunks)
  • Tests/AblyChatTests/ably-common (1 hunks)
✅ Files skipped from review due to trivial changes (3)
  • .gitmodules
  • .prettierignore
  • Tests/AblyChatTests/ably-common
🔇 Additional comments (3)
Package.swift (2)

Line range hint 19-24: Consider switching ably-cocoa to a tagged version before integration tests.

The TODO comment indicates using a branch instead of a tag. For integration tests, it's particularly important to pin dependencies to specific versions to ensure test stability and reproducibility.

Let's check the available tags for ably-cocoa:

#!/bin/bash
# Description: Check available stable tags for ably-cocoa

echo "Fetching latest tags from ably-cocoa repository:"
gh api repos/ably/ably-cocoa/tags --jq '.[].name' | grep -v beta | grep -v alpha | head -n 5

Consider prioritizing issue #80 to switch to a stable tagged version before implementing the integration test suite.


61-63: LGTM! Verify resource path matches submodule.

The addition of the ably-common resource to the test target is correct and aligns with the integration testing objectives.

Let's verify the resource path matches the submodule location:

✅ Verification successful

Resource path correctly matches submodule location ✓

The verification confirms that:

  • The submodule is correctly configured at Tests/AblyChatTests/ably-common
  • The directory exists at the expected location
  • The resource path in Package.swift is correctly referenced relative to the test target
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the ably-common submodule location matches the resource path

# Test: Check if the submodule exists at the expected path
if [ -f ".gitmodules" ]; then
    echo "Checking .gitmodules content:"
    cat .gitmodules
fi

# Test: Verify the directory structure
echo -e "\nChecking directory structure:"
ls -la Tests/AblyChatTests/ably-common 2>/dev/null || echo "Directory not found at expected path"

Length of output: 334


Script:

#!/bin/bash
# Let's try a different approach to verify the submodule and resource path

# Check if .gitmodules exists and its contents
if [ -f ".gitmodules" ]; then
    echo "=== .gitmodules content ==="
    cat .gitmodules
else
    echo ".gitmodules file not found"
fi

echo -e "\n=== Directory structure ==="
# List contents of the root directory to see ably-common
ls -la | grep "ably-common"

# Try to find ably-common directory anywhere in the repository
echo -e "\n=== Finding ably-common directory ==="
fd "ably-common" --type d

# Check Package.swift content around the resource declaration
echo -e "\n=== Package.swift context ==="
rg -C 5 "\.copy\(\"ably-common\"\)" Package.swift

Length of output: 917

.github/workflows/check.yaml (1)

20-21: LGTM! Consistent submodule support added across all jobs.

The addition of submodules: true to all actions/checkout@v4 steps is correct and necessary to support the new integration tests that depend on the ably-common submodule.

Let's verify that all checkout actions have been updated:

Also applies to: 47-48, 66-67, 87-88, 108-109, 128-129

✅ Verification successful

Let me gather more context to verify if these checkout actions are properly configured with submodules support.


All checkout actions correctly configured with submodule support

The verification confirms that all six instances of actions/checkout@v4 in the workflow file are properly configured with submodules: true. This is consistent with the changes needed to support the new integration tests that depend on the ably-common submodule.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that all checkout actions include submodule support
# Expected: All checkout actions should have the submodules parameter

# Search for checkout actions without submodule support
echo "Checking for any checkout actions without submodule support..."
rg "uses: actions/checkout@v4\s*$" .github/workflows/check.yaml

# If any are found, they will be listed above. No output means all are properly configured.

Length of output: 404


Script:

#!/bin/bash
# Get more context around the checkout actions to see their complete configuration
rg -A 2 "uses: actions/checkout@v4" .github/workflows/check.yaml

Length of output: 531

Tests/AblyChatTests/IntegrationTests.swift Show resolved Hide resolved
Tests/AblyChatTests/IntegrationTests.swift Outdated Show resolved Hide resolved
Tests/AblyChatTests/Helpers/Sandbox.swift Show resolved Hide resolved
Tests/AblyChatTests/Helpers/Sandbox.swift Show resolved Hide resolved
Tests/AblyChatTests/Helpers/Sandbox.swift Show resolved Hide resolved
Tests/AblyChatTests/Helpers/Sandbox.swift Show resolved Hide resolved
Tests/AblyChatTests/Helpers/Sandbox.swift Show resolved Hide resolved
@lawrence-forooghian lawrence-forooghian force-pushed the basic-integration-tests branch 2 times, most recently from 9c8d181 to 6f69d1d Compare November 7, 2024 03:22
@lawrence-forooghian lawrence-forooghian requested review from maratal and umair-ably and removed request for maratal and umair-ably November 7, 2024 03:24
Copy link

@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

🧹 Outside diff range and nitpick comments (1)
Tests/AblyChatTests/IntegrationTests.swift (1)

7-7: Offer assistance with implementing a timeout function

Noticed that you considered adding a timeout to the tests but deferred due to compatibility concerns. If you'd like, I can help provide a custom timeout implementation that's compatible with earlier iOS versions.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 67d4145 and 6f69d1d.

📒 Files selected for processing (8)
  • .github/workflows/check.yaml (6 hunks)
  • .gitmodules (1 hunks)
  • .prettierignore (1 hunks)
  • CONTRIBUTING.md (2 hunks)
  • Package.swift (1 hunks)
  • Tests/AblyChatTests/Helpers/Sandbox.swift (1 hunks)
  • Tests/AblyChatTests/IntegrationTests.swift (1 hunks)
  • Tests/AblyChatTests/ably-common (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (7)
  • .github/workflows/check.yaml
  • .gitmodules
  • .prettierignore
  • CONTRIBUTING.md
  • Package.swift
  • Tests/AblyChatTests/Helpers/Sandbox.swift
  • Tests/AblyChatTests/ably-common
🔇 Additional comments (2)
Tests/AblyChatTests/IntegrationTests.swift (2)

28-34: Consider using dynamic room IDs to avoid test interference

Using a static room ID like "basketball" may cause test interference when running tests concurrently or multiple times. Generating a unique room ID for each test can prevent potential conflicts.


24-68: Add resource cleanup to prevent potential leaks

The test creates chat clients but doesn't clean them up after execution. This could lead to resource leaks in the testing environment. Consider adding cleanup code to close clients and release resources after the test completes.

@lawrence-forooghian lawrence-forooghian marked this pull request as draft November 7, 2024 03:27
@lawrence-forooghian
Copy link
Collaborator Author

lawrence-forooghian commented Nov 7, 2024

Something is intermittently failing; will investigate. Putting back to draft.

It’s unlikely that we’re going to have a working unified test suite
before the beta release, so here are some very basic smoke tests just to
give us a _little bit_ of confidence that things are kind of working and
that we don’t introduce major regressions.

Would be good to have a way of separating these from the unit tests so
that they don’t slow them down, but can figure that out later; I don’t
have loads of time to spend on this at the moment.
@lawrence-forooghian lawrence-forooghian marked this pull request as ready for review November 7, 2024 12:35
@lawrence-forooghian
Copy link
Collaborator Author

OK, ready now.

Base automatically changed from fix-Message-createdAt-decoding to main November 7, 2024 12:37
Copy link
Collaborator

@maratal maratal left a comment

Choose a reason for hiding this comment

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

LGTM

@lawrence-forooghian lawrence-forooghian merged commit 26b38a4 into main Nov 7, 2024
12 checks passed
@lawrence-forooghian lawrence-forooghian deleted the basic-integration-tests branch November 7, 2024 13:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants