Repository navigation
Answers: test the poll in answer (rejected, empty, no answer, read error) - #167
Merged
Merged
Conversation
Camera::answer read the device directly, so no test reached its arms. The poll is now poll_answer, which takes the selector-2 read as a closure and the gap as an argument; Camera::answer passes the device read and the same 50 ms gap, so what is sent and read on the camera is unchanged. Tests script the replies: a rejected answer returns Error::Rejected(command, code) at the first read, an empty answer returns an empty list, a stale answer runs through all 20 reads to NoAnswer, and failed reads are polled again until a value arrives. Fixes #151 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The test module already gets XU_SIZE through use super::*. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #151
What changed
Camera::answerread selector 2 straight from the device, so no test reached its arms. The poll body moved intopoll_answer(command, seq, gap, read)incrates/obsbot-device/src/family/exchange.rs;readis a closure returning one selector-2 read, so a test can script the replies.Camera::answercalls it withREPLY_GAP(50 ms) and|| self.dev.xu_get(2): same sleep before every read, same 20 attempts, same read, nothing sent. Production code otherwise unchanged.The seam is deliberately small (one function, one closure) so that #152 (stacked on this branch) can use it.
New tests (module
exchange::tests):Error::Rejected(command, code)(code -3) after exactly one readError::NoAnswer(command)How it was verified
Gate, on this branch:
cargo fmt --check,cargo clippy --all-targets --locked -- -D warnings,cargo test --locked: all green.tests/byte_guard.rsandtests/cli_surface.rspass with their fixtures unchanged.Mutations by hand in
poll_answer(each reverted afterwards; the file is identical to the committed one):Some(Answer::Rejected(code)) => return Err(...)replaced bySome(Answer::Rejected(_)) => {}(the issue's mutant)a_rejected_answer_returns_the_cameras_code_at_the_first_pollFAILED0Answer::Emptyarm replaced by{}an_empty_answer_is_an_empty_list_not_a_missing_oneFAILEDread()?)a_failed_read_is_polled_again_and_a_later_value_is_returnedFAILEDREPLY_ATTEMPTS20 to 19without_a_matching_answer_the_poll_gives_up_after_all_attemptsFAILEDWith the current code all four tests pass. No CHANGELOG line: tests only, nothing a user can see. No camera needed; the tests open no device.
🤖 Generated with Claude Code