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 Streaming Client interaction test #4132

Merged
merged 4 commits into from
Jun 27, 2024
Merged

Conversation

udsamani
Copy link
Collaborator

With this change, we are adding tests for interaction between the producer and consumer client.
The test scenarion being added is where we kill the consumer client and make sure that producer client kills the stream as well

@udsamani udsamani self-assigned this Jun 24, 2024
Copy link

coderabbitai bot commented Jun 24, 2024

Important

Review skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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

With this change, we are adding tests for interaction
between the producer and consumer client.
The test scenarion being added is where we kill the consumer client
and make sure that producer client kills the stream as well
@udsamani udsamani requested review from frrist and wdbaruni June 24, 2024 10:29
@udsamani udsamani linked an issue Jun 24, 2024 that may be closed by this pull request
Comment on lines 137 to 138
log.Ctx(ctx).Err(err).Msg("heartbeat request to consumer client timed out")
nonActiveStreamIds[c] = append(nonActiveStreamIds[c], activeStreamIds...)
Copy link
Member

Choose a reason for hiding this comment

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

does this mean we close all streams the first time we fail to heartbeat? There can be an area of improvement here we should only close streams that fail N consecutive heartbeats, where N can equal to 3 by default

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Makes sense. I already have an issue opened for optimising this ! Will solve it as part of that ! #4026

Comment on lines 119 to 121
for streamId, streamInfo := range streamInfoMap {
activeStreamIds = append(activeStreamIds, streamId)
activeStreamIdsByReqSubj[streamInfo.RequestSub] = append(activeStreamIdsByReqSubj[streamInfo.RequestSub], streamInfo.ID)
Copy link
Member

Choose a reason for hiding this comment

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

is streamInfo.ID the same as streamId?

There are too many maps in ProducerClient, activeStreamInfo and activeConnHeartBeatRequestSubjects, but still they are not enough as we have to construct this activeStreamIdsByReqSubj with every heartbeat. Is there anything we can do to make things more readable? If having two maps already are not making things more readable or efficient as we still have to loop here, does it make sense to just have one activeStreamInfo type and have helper methods that return grouped by streams on-demand?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Let me revisit it !

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Made it more readable!

Comment on lines 149 to 152
nonActiveStreamIdsFromConsumer := getStringList(heartBeatResponse.NonActiveStreamIds)
if len(nonActiveStreamIdsFromConsumer) != 0 {
nonActiveStreamIds[c] = append(nonActiveStreamIds[c], nonActiveStreamIdsFromConsumer...)
}
Copy link
Member

Choose a reason for hiding this comment

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

why do we expect nonActiveStreamIds to have values for the same consumer from a previous loop iteration?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not sure I understand. This is still happening in the same loop right ! We are just flattening the map. The loop is for different consumers!

Copy link
Member

Choose a reason for hiding this comment

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

What I mean is nonActiveStreamIds[c] = append(nonActiveStreamIds[c], nonActiveStreamIdsFromConsumer...) effectively the same as nonActiveStreamIds[c] = nonActiveStreamIdsFromConsumer because nonActiveStreamIds[c] is only populated once

Comment on lines 69 to 72
Config: StreamProducerClientConfig{
HeartBeatIntervalDuration: 2 * time.Second,
HeartBeatRequestTimeout: 1 * time.Second,
StreamCancellationBufferDuration: 2 * time.Second,
Copy link
Member

Choose a reason for hiding this comment

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

feel free to adjust these values to speed up the test if they are too slow

@udsamani udsamani marked this pull request as ready for review June 25, 2024 20:46
@udsamani udsamani requested a review from wdbaruni June 25, 2024 20:47
Comment on lines 98 to 101
activeStreamIdsForConn := pc.activeConsumers[consumerID].ActiveStreamInfo
if activeStreamIdsForConn == nil {
return
}
Copy link
Member

Choose a reason for hiding this comment

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

can this return nil pointer exception if no entry for for consumerID is found?

Comment on lines 149 to 152
nonActiveStreamIdsFromConsumer := getStringList(heartBeatResponse.NonActiveStreamIds)
if len(nonActiveStreamIdsFromConsumer) != 0 {
nonActiveStreamIds[c] = append(nonActiveStreamIds[c], nonActiveStreamIdsFromConsumer...)
}
Copy link
Member

Choose a reason for hiding this comment

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

What I mean is nonActiveStreamIds[c] = append(nonActiveStreamIds[c], nonActiveStreamIdsFromConsumer...) effectively the same as nonActiveStreamIds[c] = nonActiveStreamIdsFromConsumer because nonActiveStreamIds[c] is only populated once

@udsamani udsamani requested a review from wdbaruni June 26, 2024 21:13
@udsamani udsamani merged commit 0eedc64 into main Jun 27, 2024
9 of 12 checks passed
@udsamani udsamani deleted the nat-streaming-clients-test branch June 27, 2024 11:01
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.

Add end to end tests using streaming client interactions
2 participants