void verify_retry_results(wa::storage::retry_policy policy, web::http::status_code primary_status_code, web::http::status_code secondary_status_code, wa::storage::location_mode mode, std::function<std::chrono::milliseconds (int)> allowed_delta, std::vector<wa::storage::retry_info> expected_retry_info_list) { auto initial_location = get_initial_location(mode); auto next_location = get_next_location(mode, initial_location); wa::storage::operation_context op_context; wa::storage::request_result result(utility::datetime::utc_now(), initial_location, web::http::http_response(initial_location == wa::storage::storage_location::secondary ? secondary_status_code : primary_status_code), false); int retry_count = 0; for (auto iter = expected_retry_info_list.cbegin(); iter != expected_retry_info_list.cend(); ++iter) { auto retry_info = policy.evaluate(wa::storage::retry_context(retry_count++, result, next_location, mode), op_context); CHECK(retry_info.should_retry()); CHECK(iter->target_location() == retry_info.target_location()); CHECK(iter->updated_location_mode() == retry_info.updated_location_mode()); CHECK_CLOSE(iter->retry_interval().count(), retry_info.retry_interval().count(), allowed_delta(retry_count).count()); std::this_thread::sleep_for(retry_info.retry_interval()); result = wa::storage::request_result(utility::datetime::utc_now(), retry_info.target_location(), web::http::http_response(retry_info.target_location() == wa::storage::storage_location::secondary ? secondary_status_code : primary_status_code), false); mode = retry_info.updated_location_mode(); next_location = get_next_location(mode, next_location); } auto retry_info = policy.evaluate(wa::storage::retry_context(retry_count++, result, next_location, mode), op_context); CHECK(!retry_info.should_retry()); }
// verify_surface - returns true if surface procedure has been completed bool Sub::verify_surface(const AP_Mission::Mission_Command& cmd) { bool retval = false; switch (auto_surface_state) { case AUTO_SURFACE_STATE_GO_TO_LOCATION: // check if we've reached the location if (wp_nav.reached_wp_destination()) { // Set target to current xy and zero depth // TODO get xy target from current wp destination, because current location may be acceptance-radius away from original destination Location_Class target_location(cmd.content.location.lat, cmd.content.location.lng, 0, Location_Class::ALT_FRAME_ABOVE_HOME); auto_wp_start(target_location); // advance to next state auto_surface_state = AUTO_SURFACE_STATE_ASCEND; } break; case AUTO_SURFACE_STATE_ASCEND: if (wp_nav.reached_wp_destination()) { retval = true; } break; default: // this should never happen // TO-DO: log an error retval = true; break; } // true is returned if we've successfully surfaced return retval; }