Skip to content

metarepos: simplify metarepos tests by refactoring dummy mocks and improving test strategy #1104

Open
@ijsong

Description

@ijsong

Problem

The extensive use of manually-written dummy mock objects (e.g., dummyMetadataRepository, dummyStorageNodeClientFactory, dummyStorageNodeClient) across pkg/varlog/metarepos and related package tests is a significant source of complexity and a bottleneck for development.

These dummy objects present several problems:

  • Overly complex: They mimic substantial internal logic of real components, including state management and asynchronous behavior (via channels), making tests hard to understand and debug.
  • Hard to maintain: Changes to dummy objects can have widespread, unintended consequences across numerous tests.
  • Error-prone: The complexity of dummy objects themselves can introduce bugs into the tests.
  • Inconsistent: They deviate from standard mocking practices (like gomock), increasing the learning curve for new contributors.
  • Blurring test boundaries: Many tests using these mocks have become de-facto integration tests, losing the focus of unit testing.

This situation severely impacts developer productivity, making it difficult to write, understand, and modify tests efficiently.

Goals

The primary goal is to refactor these tests to improve clarity, maintainability, and developer productivity. We aim to:

  • Replace dummy objects with gomock: Transition to gomock for clear, interface-based mocking in unit tests.
  • Simplify unit tests: Focus unit tests on specific functions/methods with minimal, well-defined mock setups.
  • Redesign and isolate integration tests: Separate tests verifying interactions between multiple components into dedicated integration tests. These should use real component instances or minimal, well-defined test helpers.
  • Improve test readability: Make tests easier to understand by removing unnecessary complexity.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions