Skip to content

Improve tests#836

Merged
lucacome merged 7 commits intomasterfrom
tests/fix-failures
Apr 18, 2025
Merged

Improve tests#836
lucacome merged 7 commits intomasterfrom
tests/fix-failures

Conversation

@lucacome
Copy link
Copy Markdown
Member

@lucacome lucacome commented Apr 18, 2025

Summary by CodeRabbit

  • Bug Fixes

    • Improved detection and handling of container readiness during testing, resulting in more reliable test execution.
    • Enhanced error handling for Docker and gRPC connections in tests.
  • Tests

    • Deferred creation of gRPC connections until needed, improving resource management in test setup and teardown.
    • Added more robust methods for managing test environment lifecycle and container polling.
  • Chores

    • Updated test environment configurations with explicit container names for consistency.
    • Modified Docker build commands in testing to ensure images are loaded locally after build.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 18, 2025

Walkthrough

The Makefile was updated to include the --load flag in all docker build commands under the test target, ensuring built images are loaded into the local Docker image store. In the test/nginx_opentracing_test.py file, the test suite was refactored to defer the creation of the gRPC connection until it is actually needed, with new methods for setting up the connection and waiting for containers to be ready. The container readiness check was improved, and error handling around Docker and gRPC operations was enhanced. The management of the gRPC connection lifecycle was also made more robust. Additionally, the docker-compose.yaml for the test environment was modified to assign explicit fixed container names to all services.

Changes

File(s) Change Summary
Makefile Added --load flag to all docker build commands in the test target to load images into the local Docker image store.
test/nginx_opentracing_test.py Deferred gRPC connection creation, added _setup_grpc and wait_for_containers methods, improved container readiness and error handling, and enhanced gRPC connection lifecycle management.
test/environment/docker-compose.yaml Added explicit container_name properties to all services (nginx, backend, php_fpm, grpc_backend) to fix container names.

Sequence Diagram(s)

sequenceDiagram
    participant TestRunner
    participant Docker
    participant gRPCServer

    TestRunner->>Docker: wait_for_containers()
    Docker-->>TestRunner: Containers ready

    TestRunner->>TestRunner: _setup_grpc() (on demand)
    TestRunner->>gRPCServer: Establish gRPC connection
    gRPCServer-->>TestRunner: Connection ready

    TestRunner->>gRPCServer: Run gRPC test
    gRPCServer-->>TestRunner: Test result

    TestRunner->>TestRunner: Close gRPC connection (if created)
    TestRunner->>Docker: Stop containers
Loading

Tip

⚡💬 Agentic Chat (Pro Plan, General Availability)
  • We're introducing multi-step agentic chat in review comments and issue comments, within and outside of PR's. This feature enhances review and issue discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments and add commits to existing pull requests.

📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 0c4bc05 and e48947c.

📒 Files selected for processing (1)
  • test/nginx_opentracing_test.py (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • test/nginx_opentracing_test.py
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: System Testing
  • GitHub Check: Build Docker Image (alpine)
  • GitHub Check: Build Docker Image (debian)
  • GitHub Check: Build Docker Image
  • GitHub Check: Analyze (go)

🪧 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 generate docstrings to generate docstrings for 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.

@github-actions github-actions bot added the tests label Apr 18, 2025
Copy link
Copy Markdown
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 (5)
test/nginx_opentracing_test.py (5)

7-7: Remove unused sys import

sys is no longer referenced after the refactor – Ruff correctly flags this.

-import sys
🧰 Tools
🪛 Ruff (0.8.2)

7-7: sys imported but unused

Remove unused import: sys

(F401)


59-64: time.sleep(5) TODO is still present

wait_for_containers() already polls Docker; consider extending it with a health‑check for the backend instead of this fixed delay to shave 5 s off every test run.


71-101: Minor efficiency / correctness suggestions for wait_for_containers

  1. The polling loop is tight; using time.sleep(1) after the first quick iterations saves CPU without impacting total wait time.
  2. Docker can report running while a container health‑check is still starting. Consider inspecting container.attrs["State"]["Health"]["Status"] == "healthy" when the container defines a health‑check.
  3. When re‑raising after an API error (lines 98‑101) use raise … from e for better traceability.

No functional blocker, but worth tightening.

🧰 Tools
🪛 Ruff (0.8.2)

99-99: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling

(B904)


149-152: Guard clause can be simplified

You already test if self.grpcConn: inside tearDown; assigning to a local variable is unnecessary.

-        if self.grpcConn:
-            self.grpcConn.close()
+        if self.grpcConn is not None:
+            self.grpcConn.close()

(Nitpick – feel free to ignore.)


154-158: Avoid double‑closing the gRPC channel

tearDown() and _stopDocker() both close self.grpcConn. Because tearDown() calls _stopDocker() first, the second close attempt is harmless but redundant. Consider removing the close in tearDown() to keep ownership in one place.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 001e5de and 6b82df1.

📒 Files selected for processing (3)
  • Makefile (1 hunks)
  • test/nginx_opentracing_test.py (6 hunks)
  • test/requirements.ci.txt (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
test/nginx_opentracing_test.py (2)
test/environment/grpc/app_pb2_grpc.py (3)
  • AppStub (8-21)
  • CheckTraceHeader (27-31)
  • CheckTraceHeader (52-66)
test/environment/grpc/app.py (1)
  • CheckTraceHeader (14-19)
🪛 Ruff (0.8.2)
test/nginx_opentracing_test.py

7-7: sys imported but unused

Remove unused import: sys

(F401)


99-99: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling

(B904)


135-135: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling

(B904)


270-270: Local variable e is assigned to but never used

Remove assignment to unused variable e

(F841)

⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: System Testing
  • GitHub Check: Build Docker Image
  • GitHub Check: Build Docker Image (debian)
  • GitHub Check: Build Docker Image (alpine)
  • GitHub Check: Analyze (go)
🔇 Additional comments (2)
test/requirements.ci.txt (1)

1-1: Confirm that the new dependency is truly required & well‑scoped

absl-py often drags in additional transitive deps and can clash with google‑protobuf versions.
Because it is introduced only to silence log messages, double‑check:

  1. The library is not already present indirectly (to avoid duplicates / version skew).
  2. No runtime code path outside the test‑suite imports it (otherwise it should move to the main requirements.txt).

If it is strictly test‑only, keeping it here is fine.

Makefile (1)

16-18: 👍 --load flag addition looks correct

Explicitly loading the images into the local store removes the previous friction when the tests spawn containers with the docker run/compose CLI.
No further issues spotted.

Comment thread test/nginx_opentracing_test.py
Comment thread test/nginx_opentracing_test.py Outdated
Comment thread test/nginx_opentracing_test.py Outdated
lucacome and others added 2 commits April 17, 2025 22:08
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Copy link
Copy Markdown
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

♻️ Duplicate comments (1)
test/nginx_opentracing_test.py (1)

267-276: LGTM: Improved exception handling in gRPC test

The testGrpcPropagation method has been refactored to use a try-finally pattern that ensures the gRPC connection is always properly closed, regardless of whether an exception occurs. This addresses a previous review comment about exception handling and unused variables.

🧹 Nitpick comments (2)
test/nginx_opentracing_test.py (2)

7-7: Remove unused import

The sys module is imported but not used anywhere in the code.

-import sys
🧰 Tools
🪛 Ruff (0.8.2)

7-7: sys imported but unused

Remove unused import: sys

(F401)


73-103: Fix exception handling in Docker API error case

The container readiness check implementation is robust, but should preserve the original exception when raising the timeout error.

            except docker.errors.APIError as e:
                if time.time() > timeout:
-                    raise TimeoutError(f"Docker API error: {str(e)}")
+                    raise TimeoutError(f"Docker API error: {str(e)}") from e
                time.sleep(0.5)
🧰 Tools
🪛 Ruff (0.8.2)

101-101: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling

(B904)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 6b82df1 and 82cc8a4.

📒 Files selected for processing (1)
  • test/nginx_opentracing_test.py (6 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
test/nginx_opentracing_test.py (2)
test/environment/grpc/app_pb2_grpc.py (3)
  • AppStub (8-21)
  • CheckTraceHeader (27-31)
  • CheckTraceHeader (52-66)
test/environment/grpc/app.py (1)
  • CheckTraceHeader (14-19)
🪛 Ruff (0.8.2)
test/nginx_opentracing_test.py

7-7: sys imported but unused

Remove unused import: sys

(F401)


101-101: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling

(B904)

⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: Build Docker Image (alpine)
  • GitHub Check: Build Docker Image (debian)
  • GitHub Check: Build Docker Image
  • GitHub Check: Analyze (go)
🔇 Additional comments (4)
test/nginx_opentracing_test.py (4)

18-26: LGTM: Fixed import-time absl handling

This implementation correctly wraps the absl import within the try/except block, addressing a previous review comment about the import raising before the exception handler could catch it. The new code properly handles the optional dependency case, with good comments and clear module aliasing.


61-61: LGTM: Improved container readiness checking and deferred gRPC connection

The changes separate container readiness checking into a dedicated method and defer gRPC connection initialization until needed, which are both good practices for resource management.

Also applies to: 70-70


130-139: LGTM: Well-implemented gRPC lazy initialization

The _setup_grpc method properly implements lazy initialization of the gRPC connection with appropriate timeout handling and error propagation. The use of raise ... from err correctly preserves the original exception context.


151-154: LGTM: Improved gRPC connection cleanup

The changes ensure that the gRPC connection is properly closed in both tearDown and _stopDocker only when it exists, which prevents potential NoneType errors and improves resource management.

Also applies to: 156-160

Copy link
Copy Markdown
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

🧹 Nitpick comments (3)
test/nginx_opentracing_test.py (3)

50-55: Remove the now‑redundant fixed sleep() to speed up the suite

wait_for_containers() already blocks until the services are running, so the extra five‑second delay is unnecessary and slows every test class instantiation.

-        # Wait so that backend can come up.
-        # TODO: replace with something better
-        time.sleep(5)

140-143: Consistency nit: prefer explicit is not None check

Elsewhere (_stopDocker) you use is not None; mirroring that here avoids relying on a truthy evaluation of the channel object.

-        if self.grpcConn:
+        if self.grpcConn is not None:

145-149: Duplicate connection‑closing logic – keep it in one place

Both _stopDocker() and tearDown() close the gRPC channel. Because tearDown() calls _stopDocker() first, the second check is almost always a no‑op. Centralising this responsibility in _stopDocker() would reduce maintenance overhead.

Option A (simplest): remove lines 140‑143 from tearDown().
Option B: have tearDown() close the channel and let _stopDocker() assume it is already handled.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 82cc8a4 and f2017e4.

📒 Files selected for processing (1)
  • test/nginx_opentracing_test.py (4 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: Build Docker Image (debian)
  • GitHub Check: Build Docker Image (alpine)
  • GitHub Check: Build Docker Image
  • GitHub Check: Analyze (go)
  • GitHub Check: System Testing
🔇 Additional comments (3)
test/nginx_opentracing_test.py (3)

58-60: Lazy gRPC initialisation is a solid improvement

Deferring channel creation eliminates work for the many tests that never exercise gRPC. Nice change!


119-128: Exception chaining LGTM – Ruff B904 satisfied

The new _setup_grpc() correctly re‑raises with from err, preserving the original FutureTimeoutError.


256-264: Try/finally wrapper correctly guarantees channel cleanup

The new pattern ensures the channel is closed even if the RPC raises, addressing the earlier resource‑leak concern.

Comment thread test/nginx_opentracing_test.py
@lucacome lucacome merged commit 667c152 into master Apr 18, 2025
32 of 35 checks passed
@lucacome lucacome deleted the tests/fix-failures branch April 18, 2025 05:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant