|
1 | 1 | use anyhow::Result; |
2 | 2 | use std::ptr::NonNull; |
| 3 | +use std::thread; |
3 | 4 | use wasmtime::component::{self, Component}; |
4 | 5 | use wasmtime::{ |
5 | 6 | Caller, Config, Engine, Func, FuncType, Instance, Module, Store, Trap, Val, ValType, |
@@ -411,47 +412,12 @@ fn pulley_provenance_test_components() -> Result<()> { |
411 | 412 | } |
412 | 413 |
|
413 | 414 | async fn sleep(duration: std::time::Duration) { |
414 | | - // TODO: We should be able to use `tokio::time::sleep` here, but as of this |
415 | | - // writing the miri-compatible version of `wasmtime-fiber` uses threads |
416 | | - // behind the scenes, which means thread-local storage is not preserved when |
417 | | - // we switch fibers, and that confuses Tokio. If we ever fix that we can |
418 | | - // stop using our own, special version of `sleep` and switch back to the |
419 | | - // Tokio version. |
420 | | - |
421 | | - use std::{ |
422 | | - future, |
423 | | - sync::{ |
424 | | - Arc, Mutex, |
425 | | - atomic::{AtomicU32, Ordering::SeqCst}, |
426 | | - }, |
427 | | - task::Poll, |
428 | | - thread, |
429 | | - }; |
430 | | - |
431 | | - let state = Arc::new(AtomicU32::new(0)); |
432 | | - let waker = Arc::new(Mutex::new(None)); |
433 | | - future::poll_fn(move |cx| match state.load(SeqCst) { |
434 | | - 0 => { |
435 | | - state.store(1, SeqCst); |
436 | | - let state = state.clone(); |
437 | | - *waker.lock().unwrap() = Some(cx.waker().clone()); |
438 | | - let waker = waker.clone(); |
439 | | - thread::spawn(move || { |
440 | | - thread::sleep(duration); |
441 | | - state.store(2, SeqCst); |
442 | | - let waker = waker.lock().unwrap().clone().unwrap(); |
443 | | - waker.wake(); |
444 | | - }); |
445 | | - Poll::Pending |
446 | | - } |
447 | | - 1 => { |
448 | | - *waker.lock().unwrap() = Some(cx.waker().clone()); |
449 | | - Poll::Pending |
450 | | - } |
451 | | - 2 => Poll::Ready(()), |
452 | | - _ => unreachable!(), |
453 | | - }) |
454 | | - .await; |
| 415 | + let (tx, rx) = tokio::sync::oneshot::channel(); |
| 416 | + thread::spawn(move || { |
| 417 | + thread::sleep(duration); |
| 418 | + tx.send(()).unwrap(); |
| 419 | + }); |
| 420 | + rx.await.unwrap() |
455 | 421 | } |
456 | 422 |
|
457 | 423 | #[tokio::test] |
|
0 commit comments