Skip to content

Conversation

@krtab
Copy link
Contributor

@krtab krtab commented Oct 3, 2025

Summary

This PR adds a comprehensive test suite for the Synchronizer library using the Alcotest framework, along with code coverage measurement using bisect_ppx.

Changes

  • Test Suite: Added 15 tests covering all major functionality:

    • Basic operations (empty queue, single/multiple items)
    • Pledge mechanics (manual pledges, automatic creation, blocking behavior)
    • work_while helper function
    • Close functionality
    • Concurrent operations (producer/consumer, multiple workers, graph traversal)
    • Stress testing (1000 items with 8 workers)
  • Dependencies:

    • Added alcotest as a test dependency
    • Added bisect_ppx instrumentation for code coverage
  • Coverage: Achieves 100% code coverage (35/35 points)

Test Organization

Tests are organized into 6 test suites:

  1. Basic operations
  2. Pledge mechanics
  3. work_while
  4. Close functionality
  5. Concurrent operations
  6. Stress tests

Running Tests

# Run all tests
dune runtest

# Run with coverage
dune runtest --instrument-with bisect_ppx --force
bisect-ppx-report summary
bisect-ppx-report html  # Generate HTML report in _coverage/

All tests pass successfully and verify thread-safe operations, pledge management, synchronization primitives, and proper termination conditions across multiple domains.

🤖 Generated with Claude Code

Co-Authored-By: Claude noreply@anthropic.com

@redianthus
Copy link
Member

💀

@krtab
Copy link
Contributor Author

krtab commented Oct 3, 2025

J'ai rien relu yolomdr

krtab and others added 3 commits October 3, 2025 14:52
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Extract synchronizer creation into helper functions
- Add make_queue_sync() and make_queue_sync_broadcast()
- Add make_counter_worker() for thread-safe counting
- Add run_domains() to spawn and join domain arrays
- Reduce code duplication from 474 to 329 lines
- All tests still pass

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

Co-Authored-By: Claude <noreply@anthropic.com>
Per the synchronizer documentation:
- Use Condition.signal when adding a single work unit
- Use Condition.broadcast when adding multiple work units

Since Queue.push adds exactly one item at a time, signal is
correct and more efficient. Broadcast would wake all waiting
threads unnecessarily when only one can retrieve the item.

Changes:
- Replace all Condition.broadcast with Condition.signal in queue writers
- Remove redundant make_queue_sync_broadcast function
- Add documentation explaining the choice

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

Co-Authored-By: Claude <noreply@anthropic.com>
@redianthus redianthus merged commit 7ac2f33 into OCamlPro:main Oct 3, 2025
1 check passed
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