Skip to content

aimdb-sync: characterization tests for the blocking API #198

Description

@lxsaah

Background

#46 Phase 2 rewrites SyncProducer and SyncConsumer onto a block_on seam: the per-consumer forwarder task and the std::sync::mpsc::sync_channel disappear, and SyncConsumer blocks directly on BufferReader::recv(). That is a real behavior-carrying change to the blocking semantics users depend on.

Today's aimdb-sync test suite does not pin those semantics tightly enough to catch a regression. This issue writes that safety net against the current implementation, before the rewrite, so Phase 2 has something to prove itself against.

Task

Add tests to aimdb-sync/tests/ (or extend integration_test.rs) covering:

  • Blocking get() wakes on a produce — a consumer thread blocked in get() returns the value once another thread produces, rather than spinning or missing it.
  • get_with_timeout() actually times out — returns SyncError::GetTimeout when no value arrives within the deadline, and returns the value (not a timeout) when one arrives just inside it.
  • try_get() is non-blocking — returns immediately when the buffer is empty, and returns the value when one is pending.
  • Ordering / no-loss on the blocking path — N produces followed by N get()s yield the values in order.
  • Shutdown semantics — a consumer blocked in get() when the handle is detached fails cleanly (SyncError::RuntimeShutdown) rather than hanging.

Keep the tests written against the public aimdb-sync API only — no reaching into internals — so they survive the Phase 2 rewrite unchanged. That constraint is the point of the issue.

Why it matters

This is the concrete form of acceptance criterion 4 on #46, landed early where it has the most value. It is also the best way to learn how the sync bridge actually works (runtime thread, forwarder tasks, channels) without changing any of it.

Verification

cargo test -p aimdb-sync
make check

Tests must be deterministic — no sleep-and-hope. Use generous timeouts for the negative cases and explicit synchronization for the positive ones.

Files

  • aimdb-sync/tests/integration_test.rs (or a new test file)
  • Reading material: aimdb-sync/src/{handle,producer,consumer}.rs

Metadata

Metadata

Assignees

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