Skip to content

Conversation

amithsourya
Copy link
Contributor

Summary

Implements tests for streaming message scenarios where multiple events are received from the server, addressing Issue #52. This test validates the proper handling of event streams in AI agent-to-agent communication using the A2A Protocol.

Overview

The testOnMessageStreamNewMessageMultipleEventsSuccess() method verifies that the JSON-RPC handler correctly processes a sequence of multiple events during streaming communication:

  1. Task Event (WORKING state) - Initial task state update
  2. TaskArtifactUpdateEvent - Artifact generation during task execution
  3. TaskStatusUpdateEvent (COMPLETED state) - Final task completion signal
  • Follow the CONTRIBUTING Guide.
  • Make your Pull Request title in the https://www.conventionalcommits.org/ specification.
    • Important Prefixes for release-please:
      • fix: which represents bug fixes, and correlates to a SemVer patch.
      • feat: represents a new feature, and correlates to a SemVer minor.
      • feat!:, or fix!:, refactor!:, etc., which represent a breaking change (indicated by the !) and will result in a SemVer major.
  • Ensure the tests pass
  • Appropriate READMEs were updated (if necessary)

Fixes #52 🦕


Copy link
Contributor

Summary of Changes

Hello @amithsourya, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a critical new test case to enhance the robustness of the AI agent-to-agent communication protocol. The added test specifically validates the JSON-RPC handler's capability to accurately process a sequence of distinct events, such as task state updates, artifact generation, and final task completion signals, ensuring they are handled in the correct order during a streaming session. This improvement is vital for reliable asynchronous communication between agents.

Highlights

  • New Streaming Test Case: A new test method, testOnMessageStreamNewMessageMultipleEventsSuccess, has been added to validate the JSON-RPC handler's ability to correctly process multiple events during a streaming communication session.
  • Event Sequence Validation: The test specifically verifies the proper handling and order of a Task event (in WORKING state), a TaskArtifactUpdateEvent, and a TaskStatusUpdateEvent (in COMPLETED state) within a single stream.
  • Issue Resolution: This pull request addresses and fixes Issue Add a test to JSONRPCHandlerTest for sending a streaming message where multiple events are received from the server #52, which likely pertained to the reliable handling of multi-event streaming scenarios.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request adds a valuable test case for handling multiple events in a streaming scenario. The test is well-structured and covers the intended functionality. My review includes a couple of suggestions to improve the test's robustness and maintainability. Specifically, I've pointed out a way to improve error handling within the Flow.Subscriber to prevent swallowing exceptions and make debugging easier. I've also suggested a more modern and concise way to write the assertions using JUnit 5 features.

Comment on lines 401 to 403
public void onError(Throwable throwable) {
subscription.cancel();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The onError implementation currently swallows the exception. This can cause the test to fail with a timeout, hiding the real cause of the failure. It's better to capture the error and fail the test explicitly with the actual exception.

You can achieve this by using an AtomicReference<Throwable> to store the error, releasing the CountDownLatch in onError, and then asserting that the AtomicReference is null after latch.await().

Example of what onError could look like:

@Override
public void onError(Throwable throwable) {
    error.set(throwable);
    // Release latch to prevent timeout
    while (latch.getCount() > 0) {
        latch.countDown();
    }
    subscription.cancel();
}

(This assumes error is an AtomicReference<Throwable> declared outside the subscriber). You would also need to add an assertion like Assertions.assertNull(error.get()); after the latch.await() call.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

Comment on lines 419 to 420
assertInstanceOf(Task.class, results.get(0), "First event should be a Task");
Task receivedTask = (Task) results.get(0);
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Since you are using a modern version of JUnit 5, you can make this code more concise. The assertInstanceOf method returns the casted object, which allows you to combine the assertion and the variable assignment into a single line, avoiding the explicit cast.

This simplification can be applied to the other event verifications in this test as well (for TaskArtifactUpdateEvent and TaskStatusUpdateEvent).

Suggested change
assertInstanceOf(Task.class, results.get(0), "First event should be a Task");
Task receivedTask = (Task) results.get(0);
Task receivedTask = assertInstanceOf(Task.class, results.get(0), "First event should be a Task");

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

@kabir
Copy link
Collaborator

kabir commented Oct 9, 2025

Hi @amithsourya do you agree with the Gemini comments? :-)

@amithsourya amithsourya force-pushed the issue-52-multiple-events-streaming-test branch from 806feb2 to 09c625f Compare October 9, 2025 17:37
@amithsourya
Copy link
Contributor Author

Hi @kabir, I have addressed both the comments from Gemini 😄

@kabir
Copy link
Collaborator

kabir commented Oct 10, 2025

THanks @amithsourya !

@kabir kabir merged commit eee3bb8 into a2aproject:main Oct 10, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a test to JSONRPCHandlerTest for sending a streaming message where multiple events are received from the server

3 participants