-
Notifications
You must be signed in to change notification settings - Fork 76
test: add test for streaming with multiple events #326
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
test: add test for streaming with multiple events #326
Conversation
Summary of ChangesHello @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
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this 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.
public void onError(Throwable throwable) { | ||
subscription.cancel(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
assertInstanceOf(Task.class, results.get(0), "First event should be a Task"); | ||
Task receivedTask = (Task) results.get(0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
).
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"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
Hi @amithsourya do you agree with the Gemini comments? :-) |
806feb2
to
09c625f
Compare
Hi @kabir, I have addressed both the comments from Gemini 😄 |
THanks @amithsourya ! |
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:CONTRIBUTING
Guide.fix:
which represents bug fixes, and correlates to a SemVer patch.feat:
represents a new feature, and correlates to a SemVer minor.feat!:
, orfix!:
,refactor!:
, etc., which represent a breaking change (indicated by the!
) and will result in a SemVer major.Fixes #52 🦕