Skip to content

A lightweight WebAssembly runtime that is fast, secure, and standards-compliant

[CI] handle wasi-nn CI flaky tests (#13886)

Rahul91171d315447
diff --git a/crates/wasi-nn/tests/check/mod.rs b/crates/wasi-nn/tests/check/mod.rs
index c6218e28c6..e1e676240a 100644
--- a/crates/wasi-nn/tests/check/mod.rs
+++ b/crates/wasi-nn/tests/check/mod.rs
@@ -10,6 +10,7 @@ use std::{
process::Command,
sync::Mutex,
};
+use wasmtime::bail;
#[cfg(any(feature = "onnx", all(feature = "winml", target_os = "windows")))]
pub mod onnx;
@@ -33,11 +34,20 @@ pub fn artifacts_dir() -> PathBuf {
/// Retrieve the bytes at the `from` URL and place them in the `to` file.
fn download(from: &str, to: &Path) -> wasmtime::Result<()> {
let mut curl = Command::new("curl");
- curl.arg("--location").arg(from).arg("--output").arg(to);
+ curl.arg("--location")
+ .arg("--retry")
+ .arg("4")
+ .arg("--retry-delay")
+ .arg("1")
+ .arg("--retry-max-time")
+ .arg("30")
+ .arg(from)
+ .arg("--output")
+ .arg(to);
println!("> downloading: {:?}", &curl);
- let result = curl.output().unwrap();
+ let result = curl.output()?;
if !result.status.success() {
- panic!(
+ bail!(
"curl failed: {}\n{}",
result.status,
String::from_utf8_lossy(&result.stderr)
diff --git a/crates/wasi-nn/tests/check/onnx.rs b/crates/wasi-nn/tests/check/onnx.rs
index ffe9411895..3822eceaa0 100644
--- a/crates/wasi-nn/tests/check/onnx.rs
+++ b/crates/wasi-nn/tests/check/onnx.rs
@@ -5,7 +5,7 @@ use wasmtime::{Result, error::Context as _};
/// Return `Ok` if we find the cached MobileNet test artifacts; this will
/// download the artifacts if necessary.
pub fn are_artifacts_available() -> Result<()> {
- let _exclusively_retrieve_artifacts = DOWNLOAD_LOCK.lock().unwrap();
+ let _exclusively_retrieve_artifacts = DOWNLOAD_LOCK.lock().unwrap_or_else(|e| e.into_inner());
const ONNX_BASE_URL: &str = "https://github.com/onnx/models/raw/bec48b6a70e5e9042c0badbaafefe4454e072d08/validated/vision/classification/mobilenet/model/mobilenetv2-10.onnx?download=";
diff --git a/crates/wasi-nn/tests/check/openvino.rs b/crates/wasi-nn/tests/check/openvino.rs
index bc41cd5b75..6f87aa4f65 100644
--- a/crates/wasi-nn/tests/check/openvino.rs
+++ b/crates/wasi-nn/tests/check/openvino.rs
@@ -21,7 +21,7 @@ pub fn is_installed() -> Result<()> {
/// Return `Ok` if we find the cached MobileNet test artifacts; this will
/// download the artifacts if necessary.
pub fn are_artifacts_available() -> Result<()> {
- let _exclusively_retrieve_artifacts = DOWNLOAD_LOCK.lock().unwrap();
+ let _exclusively_retrieve_artifacts = DOWNLOAD_LOCK.lock().unwrap_or_else(|e| e.into_inner());
const BASE_URL: &str = "https://download.01.org/openvinotoolkit/fixtures/mobilenet";
let artifacts_dir = artifacts_dir();
if !artifacts_dir.is_dir() {
diff --git a/crates/wasi-nn/tests/check/pytorch.rs b/crates/wasi-nn/tests/check/pytorch.rs
index 72d9818919..121e8b6872 100644
--- a/crates/wasi-nn/tests/check/pytorch.rs
+++ b/crates/wasi-nn/tests/check/pytorch.rs
@@ -5,7 +5,7 @@ use wasmtime::{Result, error::Context as _};
/// Return `Ok` if we find the cached MobileNet test artifacts; this will
/// download the artifacts if necessary.
pub fn are_artifacts_available() -> Result<()> {
- let _exclusively_retrieve_artifacts = DOWNLOAD_LOCK.lock().unwrap();
+ let _exclusively_retrieve_artifacts = DOWNLOAD_LOCK.lock().unwrap_or_else(|e| e.into_inner());
const PYTORCH_BASE_URL: &str = "https://github.com/rahulchaphalkar/libtorch-models/releases/download/v0.1/squeezenet1_1.pt";
let artifacts_dir = artifacts_dir();
if !artifacts_dir.is_dir() {