Fix optional access in reservation tests
Foundation / checks (client) (push) Successful in 4s
Foundation / checks (deploy) (push) Successful in 6s
Foundation / checks (network) (push) Successful in 4s
Foundation / checks (ecs) (push) Successful in 1m58s
Foundation / checks (tsan) (push) Successful in 8m4s
Foundation / checks (postgres) (push) Failing after 21m34s
Foundation / postgres-tools (push) Canceled after 0s
Foundation / server-image (push) Canceled after 0s
Foundation / image (push) Canceled after 0s
Foundation / checks (checks) (push) Canceled after 24m49s

This commit is contained in:
dingo
2026-10-10 16:28:27 -04:00
parent be1177cc03
commit 94edeba474
2 changed files with 18 additions and 5 deletions
+8
View File
@@ -5706,3 +5706,11 @@ explicitly checked before access. clang-format 19.1.5 dry-run, clang-tidy 19.1.5
with warnings-as-errors, GCC 13.2 Release/NDEBUG compilation with warnings-as-
errors, and `git diff --check` pass locally. PostgreSQL integration remains
unavailable in this Windows environment; awaiting CI rerun.
The next CI analysis build reached the PostgreSQL tests and reported four
`bugprone-unchecked-optional-access` errors in the life-reservation test's nested
`expected<optional<...>>` checks. Reworked those assertions to extract safe
fallback values while still checking both success/presence states. clang-format
19.1.5, clang-tidy 19.1.5 with warnings-as-errors, GCC 13.2 Release/NDEBUG
compilation with warnings-as-errors, and `git diff --check` pass locally. The
PostgreSQL test binary remains unrun locally; awaiting CI rerun.
+10 -5
View File
@@ -80,9 +80,11 @@ void run_life_reservation_store_tests() {
CHECK(reserve(2) == *conflict);
auto conflict_result =
query_primitive_life(*db, a, *lease_a, alice, control->generation, 2, 5s);
CHECK(conflict_result && *conflict_result &&
(**conflict_result).reservation.refusal == LifeRefusal::existing_life &&
!(**conflict_result).published);
const auto conflict_outcome = conflict_result.value_or(std::nullopt);
const auto conflict_value = conflict_outcome.value_or(PrimitiveLifeOutcome{});
CHECK(conflict_result.has_value() && conflict_outcome.has_value() &&
conflict_value.reservation.refusal == LifeRefusal::existing_life &&
!conflict_value.published);
CHECK(failed(reserve_primitive_life(*db, a, *lease_a, alice, 2, request, 1, 5s),
LifeReservationError::fenced));
CHECK(failed(reject_primitive_life(*db, a, *lease_a, alice, 1, request, LifeRefusal::none, 5s),
@@ -118,8 +120,11 @@ void run_life_reservation_store_tests() {
const auto moved = claim_account_control(*db, b, *lease_b, alice, 2, 2, 20000ms, 5s);
CHECK(moved);
auto moved_result = query_primitive_life(*db, b, *lease_b, alice, moved->generation, 4, 5s);
CHECK(moved_result && *moved_result && (**moved_result).reservation.region == 1 &&
(**moved_result).reservation.refusal == LifeRefusal::cancelled);
const auto moved_outcome = moved_result.value_or(std::nullopt);
const auto moved_value = moved_outcome.value_or(PrimitiveLifeOutcome{});
CHECK(moved_result.has_value() && moved_outcome.has_value() &&
moved_value.reservation.region == 1 &&
moved_value.reservation.refusal == LifeRefusal::cancelled);
const auto cancelled_retry =
reserve_primitive_life(*db, b, *lease_b, alice, moved->generation, 4, 1, 5s);
CHECK(cancelled_retry && cancelled_retry->refusal == LifeRefusal::cancelled);