Skip to content

Fix infinite loop in hierarchical term generation for brands - #200

Closed
layoutd wants to merge 2 commits into
fix/pr-174-review-feedbackfrom
debug/test-hanging-issue
Closed

Fix infinite loop in hierarchical term generation for brands#200
layoutd wants to merge 2 commits into
fix/pr-174-review-feedbackfrom
debug/test-hanging-issue

Conversation

@layoutd

@layoutd layoutd commented Feb 13, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes infinite loop issue in Term::batch_hierarchical() that caused test_batch_validation_max_size to hang indefinitely.

Problem

  • The brand feature uses deviceManufacturer() which has limited unique values
  • When generating multiple brand terms, duplicate names cause term_exists errors
  • The retry logic (--$i) would loop forever without any exit condition
  • Test generating 100 products would hang trying to create 5-10 unique brands

Solution

Added max retry limit to Term::batch_hierarchical():

  • Tracks retry attempts with $retry_count
  • Sets max retries to $amount * 10 (reasonable for duplicates)
  • Breaks loop when max retries exceeded instead of hanging
  • Maintains existing duplicate handling behavior

Test Results

  • test_batch_validation_max_size: Now passes in ~2.5s (was hanging forever)
  • ✅ All GeneratorTest: 5/5 tests pass
  • ✅ Full test suite: 103 tests, 235 assertions pass in ~10.5s

Files Changed

  • includes/Generator/Term.php: Added retry limit logic in batch_hierarchical()
  • includes/Generator/Product.php: Ensured brands use max-depth => 1 to avoid hierarchy complexity

- Added max retry limit to prevent infinite loops when generating duplicate term names
- deviceManufacturer() has limited unique values, causing term_exists errors
- Without retry limit, the --$i retry logic would loop forever
- Now breaks after amount * 10 retries to allow for reasonable duplicate attempts

Fixes test_batch_validation_max_size hanging indefinitely
@layoutd
layoutd force-pushed the fix/pr-174-review-feedback branch from ed83e0d to 330f0d1 Compare February 13, 2026 21:02
@layoutd

layoutd commented Feb 13, 2026

Copy link
Copy Markdown
Contributor Author

Closing this PR as we've addressed the issue directly in the base branch.

Instead of adding retry limits to handle deviceManufacturer()'s limited unique values (only 6), we switched to using company() which provides hundreds of unique company names. This completely avoids the duplicate term/infinite loop issue without needing additional safety logic.

The fix has been incorporated into fix/pr-174-review-feedback branch.

@layoutd layoutd closed this Feb 13, 2026
@layoutd
layoutd deleted the debug/test-hanging-issue branch February 20, 2026 16:08
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.

1 participant