Skip to content

fix: Dummy test#2300

Merged
tac0turtle merged 1 commit intomainfrom
alex/fix_deadlock_test
May 21, 2025
Merged

fix: Dummy test#2300
tac0turtle merged 1 commit intomainfrom
alex/fix_deadlock_test

Conversation

@alpe
Copy link
Copy Markdown
Contributor

@alpe alpe commented May 21, 2025

Fixes Deadlock in test

Overview

Summary by CodeRabbit

  • Refactor
    • Updated naming and visibility of certain components for improved accessibility.
    • Adjusted constructor and method signatures for consistency.
  • Tests
    • Streamlined and updated test cases for better clarity and reliability.
    • Modified test behavior to expect empty results rather than errors in specific scenarios.
    • Removed unused test and helper functions.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 21, 2025

Walkthrough

The changes export the dummySequencer type as DummySequencer, update its constructor to return a pointer to the exported type, and add an interface compliance assertion. In the test file, an unused test and helper are removed, context initialization is updated, batch submission channels are explicitly set, and error handling expectations are adjusted.

Changes

File(s) Change Summary
core/sequencer/dummy.go Renamed and exported dummySequencer to DummySequencer, updated constructor to return *DummySequencer, updated method receivers, and added interface compliance assertion.
core/sequencer/dummy_test.go Removed unused test and helper, switched context initialization to t.Context(), explicitly set batch submission channels, and relaxed error handling for non-existent rollup IDs.

Poem

In the warren of code, a change took hold,
DummySequencer now stands proud and bold.
Tests cleaned and channels set with care,
Contexts aligned, no errors to snare.
With public names, our types can gleam—
A rabbit’s hop toward a cleaner dream!
🐇✨

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (1.64.8)

Error: you are using a configuration file for golangci-lint v2 with golangci-lint v1: please use golangci-lint v2
Failed executing command with error: you are using a configuration file for golangci-lint v2 with golangci-lint v1: please use golangci-lint v2

Note

⚡️ AI Code Reviews for VS Code, Cursor, Windsurf

CodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback.
Learn more here.


Note

⚡️ Faster reviews with caching

CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 30th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.
Enjoy the performance boost—your workflow just got faster.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate sequence diagram to generate a sequence diagram of the changes in 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
Copy link
Copy Markdown
Contributor

The latest Buf updates on your PR. Results from workflow CI and Release / buf-check (pull_request).

BuildFormatLintBreakingUpdated (UTC)
✅ passed⏩ skipped✅ passed✅ passedMay 21, 2025, 3:29 PM

Comment on lines 59 to 73
t.Run("non-existent rollup ID", func(t *testing.T) {
// Try to get a batch for a non-existent rollup ID
nonExistentRollupID := []byte("non-existent-rollup")
_, err := seq.GetNextBatch(ctx, GetNextBatchRequest{
req, err := seq.GetNextBatch(ctx, GetNextBatchRequest{
RollupId: nonExistentRollupID,
})

// Should return an error
if err == nil {
t.Fatal("GetNextBatch should return an error for non-existent rollup ID")
if err != nil {
t.Fatalf("no error expected: %s", err)
}
if req == nil || req.Batch == nil {
t.Fatal("unexpected nil response")
}
if err.Error() == "" || !contains(err.Error(), "no batch found for rollup ID") {
t.Fatalf("Error message should indicate the rollup ID was not found, got: %v", err)
if len(req.Batch.Transactions) != 0 {
t.Error("batch should be empty")
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The test case name "non-existent rollup ID" and its comments suggest it's testing error handling, but the updated assertions now expect success with an empty batch. This creates a disconnect between the test's name/description and its actual behavior. Consider either:

  1. Updating the test name and comments to reflect the new expected behavior (e.g., "returns empty batch for unknown rollup ID"), or
  2. Reverting the assertions to match the original error-checking intent

This will ensure the test documentation accurately reflects what's being tested, making the code more maintainable and easier to understand for future developers.

Suggested change
t.Run("non-existent rollup ID", func(t *testing.T) {
// Try to get a batch for a non-existent rollup ID
nonExistentRollupID := []byte("non-existent-rollup")
_, err := seq.GetNextBatch(ctx, GetNextBatchRequest{
req, err := seq.GetNextBatch(ctx, GetNextBatchRequest{
RollupId: nonExistentRollupID,
})
// Should return an error
if err == nil {
t.Fatal("GetNextBatch should return an error for non-existent rollup ID")
if err != nil {
t.Fatalf("no error expected: %s", err)
}
if req == nil || req.Batch == nil {
t.Fatal("unexpected nil response")
}
if err.Error() == "" || !contains(err.Error(), "no batch found for rollup ID") {
t.Fatalf("Error message should indicate the rollup ID was not found, got: %v", err)
if len(req.Batch.Transactions) != 0 {
t.Error("batch should be empty")
}
t.Run("returns empty batch for unknown rollup ID", func(t *testing.T) {
// When requesting a batch for an unknown rollup ID, the sequencer should
// return an empty batch rather than an error
unknownRollupID := []byte("non-existent-rollup")
req, err := seq.GetNextBatch(ctx, GetNextBatchRequest{
RollupId: unknownRollupID,
})
if err != nil {
t.Fatalf("no error expected: %s", err)
}
if req == nil || req.Batch == nil {
t.Fatal("unexpected nil response")
}
if len(req.Batch.Transactions) != 0 {
t.Error("batch should be empty")
}
})

Spotted by Diamond

Is this helpful? React 👍 or 👎 to let us know.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 21, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 55.79%. Comparing base (70d8b72) to head (1c4ae79).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2300      +/-   ##
==========================================
+ Coverage   55.75%   55.79%   +0.03%     
==========================================
  Files          53       53              
  Lines        5008     5008              
==========================================
+ Hits         2792     2794       +2     
+ Misses       1931     1929       -2     
  Partials      285      285              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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

🔭 Outside diff range comments (1)
core/sequencer/dummy.go (1)

30-39: ⚠️ Potential issue

Check for uninitialized batchSubmissionChan

The method accesses s.batchSubmissionChan without checking if it's initialized. This could lead to a nil pointer panic if SetBatchSubmissionChan wasn't called.

Add a nil check to avoid potential panics:

func (s *DummySequencer) SubmitRollupBatchTxs(ctx context.Context, req SubmitRollupBatchTxsRequest) (*SubmitRollupBatchTxsResponse, error) {
	s.mu.Lock()
	defer s.mu.Unlock()

	s.batches[string(req.RollupId)] = req.Batch
-	if req.Batch != nil && len(req.Batch.Transactions) > 0 {
+	if req.Batch != nil && len(req.Batch.Transactions) > 0 && s.batchSubmissionChan != nil {
		s.batchSubmissionChan <- *req.Batch
	}
	return &SubmitRollupBatchTxsResponse{}, nil
}
🧹 Nitpick comments (1)
core/sequencer/dummy.go (1)

64-66: Consider initializing the channel in the constructor

The batchSubmissionChan is only initialized via this setter method, which could lead to bugs if someone forgets to call it before using the sequencer.

Consider initializing the channel in the constructor with a default buffer size:

func NewDummySequencer() *DummySequencer {
	return &DummySequencer{
		batches: make(map[string]*Batch),
+		batchSubmissionChan: make(chan Batch, 10), // Default buffer size
	}
}

Then update the setter to allow overriding the default:

func (s *DummySequencer) SetBatchSubmissionChan(batchSubmissionChan chan Batch) {
+	// Close existing channel if it exists and isn't the same
+	if s.batchSubmissionChan != nil && s.batchSubmissionChan != batchSubmissionChan {
+		close(s.batchSubmissionChan)
+	}
	s.batchSubmissionChan = batchSubmissionChan
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between 70d8b72 and 1c4ae79.

📒 Files selected for processing (2)
  • core/sequencer/dummy.go (3 hunks)
  • core/sequencer/dummy_test.go (7 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
core/sequencer/dummy.go (1)
sequencers/single/sequencer.go (1)
  • Sequencer (30-44)
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: rollkit-docker / docker-build (GHCR; ghcr.io/rollkit/rollkit)
  • GitHub Check: test / Run Unit Tests
  • GitHub Check: test / Build All Rollkit Binaries
  • GitHub Check: Analyze (go)
  • GitHub Check: Summary
🔇 Additional comments (9)
core/sequencer/dummy.go (3)

13-13: Good addition of interface compliance check

Adding the compile-time type assertion ensures that DummySequencer properly implements the Sequencer interface.


15-16: Export of type improves testability

Exporting the DummySequencer type makes it accessible for testing in other packages. The additional documentation clarifies its purpose.


23-24: Updated constructor return type properly matches new exported type

The constructor now correctly returns the concrete *DummySequencer type instead of the interface, which makes initialization in tests more explicit.

core/sequencer/dummy_test.go (6)

11-13: Good practice: Explicit channel initialization prevents deadlocks

Setting the batch submission channel explicitly before using it prevents potential deadlocks when sending to an uninitialized or unbuffered channel.


53-57: Improved test setup with explicit channel initialization

Setting the batch submission channel and context before the test cases improves test clarity and prevents potential deadlocks.


60-73: Updated expectations for non-existent rollup IDs

The test now correctly verifies that the sequencer returns an empty batch (with no transactions) instead of an error when querying a non-existent rollup ID. This matches the implementation behavior in the GetNextBatch method.


147-158: Fix for potential deadlock in concurrency test

The batch submission channel is now properly initialized with a sufficient buffer size to handle all concurrent operations (numGoroutines*numOperationsPerGoroutine). This prevents deadlocks that could occur if the channel were unbuffered or had insufficient capacity.


220-224: Proper channel initialization for multiple rollups test

The batch submission channel is now correctly initialized with a buffer size of 3, matching the number of rollups being tested. This prevents potential deadlocks when submitting batches.


265-268: Consistent channel initialization pattern

The batch overwrite test now follows the same pattern of explicitly initializing the batch submission channel, making the test setup consistent across all test cases.

@alpe alpe changed the title Fix dummy test fix: Dummy test May 21, 2025
@tac0turtle tac0turtle added this pull request to the merge queue May 21, 2025
Merged via the queue into main with commit 9eb9e59 May 21, 2025
29 of 31 checks passed
@tac0turtle tac0turtle deleted the alex/fix_deadlock_test branch May 21, 2025 15:58
@github-project-automation github-project-automation Bot moved this to Done in Evolve May 21, 2025
@tac0turtle tac0turtle removed this from Evolve Aug 25, 2025
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.

2 participants