Skip to content

Comments

[fix][test] Fixed Nondeterministic Assertions in KafkaAbstractSinkTest#24877

Merged
Technoboy- merged 1 commit intoapache:masterfrom
LucasEby:fix-testInvalidConfigWillThrownException
Oct 27, 2025
Merged

[fix][test] Fixed Nondeterministic Assertions in KafkaAbstractSinkTest#24877
Technoboy- merged 1 commit intoapache:masterfrom
LucasEby:fix-testInvalidConfigWillThrownException

Conversation

@LucasEby
Copy link
Contributor

Fixes #24876

Motivation

The original test performed six assertions using the expectThrows method but was based on two incorrect assumptions. First, it implicitly assumed that field validation within IOConfigUtils.java would occur in a consistent order. However, IOConfigUtils iterates over configuration fields using the loop (Field field : getAllFields(clazz)), and getAllFields() calls Class.getDeclaredFields, which returns an array of fields that are not sorted and not in any particular order. Second, the test initialized multiple required fields as null simultaneously, assuming the validation would fail in a specific order. In reality, the nondeterministic field iteration order can cause different missing fields to be detected first, leading to inconsistent exception messages and nondeterministic test failures due to different environments producing the contents in different orders despite the logical contents being the same.

  • pulsar-io/kafka/src/test/java/org/apache/pulsar/io/kafka/sink/KafkaAbstractSinkTest.java

Modifications

Instead of reusing and mutating the same map, each validation case now creates it's own copy of the valid base config data with ``validConfig``` prior to mutating it and later asserting. By isolating the mutations for each test, this ensures the behavior will be as expected. To make the code easier to read, a tiny table of cases was added (record Case(...)) which is made up of the basic components of the original test cases: how the data should be mutated, the expected exception type, and the expected message. The final sanity check which ensures the valid config passes was preserved. These changes ensure the test passes consistently, even when the fields are checked in a different order.

In essence, these changes keep the spirit of the original tests while eliminating failures caused solely by allowed (but previously unexpected) reordering.

Verifying this change

  • Make sure that the change passes the CI checks.

This change is already covered by existing tests, such as

  • pulsar-io/kafka/src/test/java/org/apache/pulsar/io/kafka/sink/KafkaAbstractSinkTest.java

Does this pull request potentially affect one of the following parts:

If the box was checked, please highlight the changes

  • Dependencies (add or upgrade a dependency)
  • The public API
  • The schema
  • The default values of configurations
  • The threading model
  • The binary protocol
  • The REST endpoints
  • The admin CLI options
  • The metrics
  • Anything that affects deployment

Documentation

  • doc
  • doc-required
  • doc-not-needed
  • doc-complete

Matching PR in forked repository

PR in forked repository: LucasEby#7

@github-actions github-actions bot added the doc-not-needed Your PR changes do not impact docs label Oct 19, 2025
@codecov-commenter
Copy link

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 74.23%. Comparing base (678db6b) to head (4e52dbd).
⚠️ Report is 3 commits behind head on master.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff              @@
##             master   #24877      +/-   ##
============================================
- Coverage     74.34%   74.23%   -0.12%     
- Complexity    33496    33815     +319     
============================================
  Files          1913     1913              
  Lines        149315   149315              
  Branches      17331    17331              
============================================
- Hits         111012   110846     -166     
- Misses        29475    29610     +135     
- Partials       8828     8859      +31     
Flag Coverage Δ
inttests 26.42% <ø> (-0.69%) ⬇️
systests 22.82% <ø> (-0.20%) ⬇️
unittests 73.75% <ø> (-0.11%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.
see 85 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Technoboy- Technoboy- merged commit 7c6a4aa into apache:master Oct 27, 2025
53 of 54 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

doc-not-needed Your PR changes do not impact docs ready-to-test type/flaky-tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Nondeterministic Assertions in KafkaAbstractSinkTest

3 participants