Skip to content

Commit f264b8a

Browse files
committed
fix: Use run_async during update_test_file
Signed-off-by: Rohan Krishnaswamy <[email protected]>
1 parent facb127 commit f264b8a

File tree

2 files changed

+25
-11
lines changed

2 files changed

+25
-11
lines changed

sqllogictest/src/parser.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,16 @@ impl<T: ColumnType> Record<T> {
206206
pub fn unparse(&self, w: &mut impl std::io::Write) -> std::io::Result<()> {
207207
write!(w, "{self}")
208208
}
209+
210+
/// Returns the retry configuration for this record, if one exists.
211+
pub fn retry_config(&self) -> Option<&RetryConfig> {
212+
match &self {
213+
Record::Statement { retry, .. }
214+
| Record::Query { retry, .. }
215+
| Record::System { retry, .. } => retry.as_ref(),
216+
_ => None,
217+
}
218+
}
209219
}
210220

211221
/// As is the standard for Display, does not print any trailing

sqllogictest/src/runner.rs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -959,18 +959,11 @@ impl<D: AsyncDB, M: MakeConnection<Conn = D>> Runner<D, M> {
959959
&mut self,
960960
record: Record<D::ColumnType>,
961961
) -> Result<RecordOutput<D::ColumnType>, TestError> {
962-
let retry = match &record {
963-
Record::Statement { retry, .. } => retry.clone(),
964-
Record::Query { retry, .. } => retry.clone(),
965-
Record::System { retry, .. } => retry.clone(),
966-
_ => None,
967-
};
968-
if retry.is_none() {
962+
// The parser ensures that `retry.attempts` must be > 0.
963+
let Some(retry) = record.retry_config() else {
969964
return self.run_async_no_retry(record).await;
970-
}
965+
};
971966

972-
// Retry for `retry.attempts` times. The parser ensures that `retry.attempts` must > 0.
973-
let retry = retry.unwrap();
974967
let mut last_error = None;
975968
for _ in 0..retry.attempts {
976969
let result = self.run_async_no_retry(record.clone()).await;
@@ -1530,7 +1523,18 @@ impl<D: AsyncDB, M: MakeConnection<Conn = D>> Runner<D, M> {
15301523
);
15311524
continue;
15321525
}
1533-
let record_output = self.apply_record(record.clone()).await;
1526+
1527+
// If a retry configuration is specified, it is safe run the record with retries
1528+
let record_output = if record.retry_config().is_some() {
1529+
// Exhaust all possible retries first before applying the record
1530+
match self.run_async(record.clone()).await {
1531+
Ok(record_output) => record_output,
1532+
Err(_) => self.apply_record(record.clone()).await,
1533+
}
1534+
} else {
1535+
self.apply_record(record.clone()).await
1536+
};
1537+
15341538
let record = update_record_with_output(
15351539
&record,
15361540
&record_output,

0 commit comments

Comments
 (0)