Skip to content

Commit

Permalink
td/util: Add async evaluate_qe
Browse files Browse the repository at this point in the history
Summary:
Avoid the hidden footgun of `run_as_sync` with a dedicated API.

Also add a warning to the sync version of the code.

Reviewed By: rjbailey

Differential Revision: D67342024

fbshipit-source-id: 023fad677c88afc9f0fed5e44ac090b30b29209f
  • Loading branch information
Aniket Mathur authored and facebook-github-bot committed Dec 17, 2024
1 parent c1ec4ad commit abda65a
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions td_util/src/qe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub enum QEParamValue {
}

#[cfg(all(fbcode_build, target_os = "linux"))]
pub fn evaluate_qe_sync(
pub async fn evaluate_qe(
unit_id: u64,
universe: &str,
param: &str,
Expand All @@ -31,7 +31,7 @@ pub fn evaluate_qe_sync(
use tracing::info;

let value_for_logging: serde_json::Value;
let qe = crate::executor::run_as_sync(QE2::from_unit_id(unit_id, &[universe]));
let qe = QE2::from_unit_id(unit_id, &[universe]).await;
let ret = match &expect {
QEParamValue::Bool(expect) => {
let qe_value = qe.get_bool(universe, param, false);
Expand Down Expand Up @@ -67,12 +67,24 @@ pub fn evaluate_qe_sync(
}

#[cfg(not(all(fbcode_build, target_os = "linux")))]
pub fn evaluate_qe_sync(
pub async fn evaluate_qe(
_unit_id: u64,
_universe: &str,
_param: &str,
_expect: QEParamValue,
_step: supertd_events::Step,
) -> bool {
return false;
false
}

/// Sync API for checking QE2.
/// This does not work from existing `run_as_sync` contexts, and will deadlock.
pub fn evaluate_qe_sync(
unit_id: u64,
universe: &str,
param: &str,
expect: QEParamValue,
step: supertd_events::Step,
) -> bool {
crate::executor::run_as_sync(evaluate_qe(unit_id, universe, param, expect, step))
}

0 comments on commit abda65a

Please sign in to comment.