Skip to content

Conversation

@JustinDFuller
Copy link
Owner

Note: This PR title, description, and code were generated with Claude Code

Summary

  • Removed the ±1 tolerance from call count assertions in blackbox tests
  • Tests pass without any failures, confirming the algorithm's precision

Background

The blackbox tests had a tolerance allowing call counts to be off by ±1:

if expected := int(1000 * (float64(second.flowRate) / 100)); calls-expected > 1 || calls-expected < -1

This tolerance appeared to be defensive coding to handle potential rounding errors in the flow control algorithm.

Analysis

After investigation, the flow control algorithm is mathematically precise:

  • Uses cumulative allowed and blocked counters
  • Calculates allowRate = (allowed * 100) / total
  • Makes deterministic allow/block decisions based on allowRate < flowRate

This creates a self-correcting feedback loop that naturally converges to the exact target rate.

Test Results

Both blackbox tests pass without any failures after removing the tolerance:

  • TestNozzleDoBoolBlackbox - PASS (68 seconds)
  • TestNozzleDoErrorBlackbox - PASS (61 seconds)

All flow rates (100%, 99%, 97%, down to 0%) produce exactly the expected number of calls.

Conclusion

The ±1 tolerance was unnecessary. The algorithm produces exact results, making this defensive code removable.

🤖 Generated with Claude Code

The flow control algorithm is mathematically precise and produces
exact call counts. Testing confirmed no off-by-one errors occur,
making the tolerance unnecessary defensive coding.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@JustinDFuller JustinDFuller merged commit 561a403 into main Sep 12, 2025
4 checks passed
@JustinDFuller JustinDFuller deleted the remove-test-tolerance branch September 12, 2025 13:39
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