Skip to content

test(eventhubs): cover consumer start positions - #5077

Draft
Johnathan W (j7nw4r) wants to merge 1 commit into
Azure:mainfrom
j7nw4r:j7nw4r/eventhubs-start-position-live-tests
Draft

test(eventhubs): cover consumer start positions#5077
Johnathan W (j7nw4r) wants to merge 1 commit into
Azure:mainfrom
j7nw4r:j7nw4r/eventhubs-start-position-live-tests

Conversation

@j7nw4r

Copy link
Copy Markdown
Member

Summary

The Event Hubs consumer live tests covered two start positions. This change adds live tests for the offset, enqueued time, and Latest positions, and for the inclusive flag. It also adds unit tests for the two filter arms that had no test.

Motivation

The start position controls where a receiver begins in a partition, and the service resolves each position type differently, so a defect in one type does not appear in the tests for another type. Today eventhubs_consumer.rs reads only from Earliest, and eventhubs_round_trip.rs reads only from a sequence number. The Earliest and Latest arms of StartPosition::start_expression have no unit test, and the Latest arm is reachable by a live test alone.

Changes

  • Add tests/eventhubs_start_position.rs with five live tests: offset exclusive, offset inclusive, enqueued time, Latest, and sequence number inclusive.
  • Tag every sent event with a per-run marker, so each test asserts on its own events and tolerates the foreign traffic that shares a partition.
  • Serialize the five tests on a file-level async mutex, because three of them seed one partition and a parallel seed moves the start boundary past a test's own events.
  • Add unit tests for the Earliest and Latest filter strings and for the no-position fallback in src/consumer/mod.rs.
  • Add the sync feature to the tokio dev-dependency, which the new test file needs for tokio::sync::Mutex.

Test plan

  • cargo test -p azure_messaging_eventhubs --lib consumer::tests::test_start_position gives 6 passed.
  • The two unit tests carry a mutation proof. A change from '-1' to '0' at src/consumer/mod.rs:594 fails the Earliest test alone. A change from '@latest' to '@Latest' at line 595 fails the first assertion of the Latest test alone. A change to the no-position fallback at line 598 fails the third assertion of that test alone.
  • The two unit tests are plain #[test] functions and need no test-proxy recording, so they pass against the assets tag that this branch pins.
  • cargo test -p azure_messaging_eventhubs --test eventhubs_start_position reports 5 ignored when AZURE_TEST_MODE is unset.
  • cargo fmt -- --check, cargo clippy --all-features --all-targets with -Dwarnings, and cargo doc --all-features --no-deps with -Dwarnings all pass.
  • The five live tests are not yet proven live. The test identity in the development environment holds no Send role on the namespace, and the same failure appears on an unchanged main, so it is the environment and not this change. To prove them, run AZURE_TEST_MODE=live cargo test -p azure_messaging_eventhubs --test eventhubs_start_position -- --test-threads=1 against a namespace where the identity can send.

Closes #4887.

Add two unit tests for the Earliest and Latest start expressions, and
five live tests for the consumer start positions on a real Event Hub.

The two unit tests are plain unit tests. StartPosition::start_expression
is a pure synchronous function, so the tests compute a string and
compare it. They need no test proxy, no recording, and no async runtime.
Each one carries a mutation proof: it was run against a broken copy of
the source and it failed with the expected assertion. The Latest test
also pins the no-position fallback, because the same literal is written
twice in start_expression and a test on one copy lets the other copy
drift.

The five live tests are not yet proven live. This environment has no
Event Hubs credential, so the tests are proven only by compilation and
by the ignore behavior in playback mode. A live run must follow before
the tests are trusted.

The live tests share two partitions, so they take a file-level mutex.
Each test reads the partition tail as its start boundary, and a test
that seeds the same partition at the same time moves that boundary past
the events of the other test. Every event carries a per-run marker, so
each test asserts on its own events and ignores the foreign traffic on
the partition.

Add the tokio sync feature to the dev-dependency, because the live
tests use tokio::sync::Mutex. That feature reached the test target only
through a transitive dependency, which can break without warning.
@j7nw4r
Johnathan W (j7nw4r) force-pushed the j7nw4r/eventhubs-start-position-live-tests branch from 7d8991c to 98cdb54 Compare August 25, 2026 18:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Event Hubs] Add live tests for consumer start positions

1 participant