MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / resume_separate_thread_tls

Function resume_separate_thread_tls

tests/all/async_functions.rs:622–661  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

620#[tokio::test]
621#[cfg_attr(miri, ignore)]
622async fn resume_separate_thread_tls() {
623 static COUNTER: AtomicUsize = AtomicUsize::new(0);
624
625 struct IncOnDrop;
626 impl Drop for IncOnDrop {
627 fn drop(&mut self) {
628 COUNTER.fetch_add(1, Ordering::SeqCst);
629 }
630 }
631
632 thread_local!(static FOO: IncOnDrop = IncOnDrop);
633
634 // This test will poll the following future on two threads.
635 // We verify that TLS destructors are run correctly.
636 execute_across_threads(async move {
637 let mut store = async_store();
638 let module = Module::new(
639 store.engine(),
640 "
641 (module
642 (import \"\" \"\" (func))
643 (start 0)
644 )
645 ",
646 )
647 .unwrap();
648 let func = Func::wrap_async(&mut store, |_, _: ()| {
649 Box::new(async {
650 tokio::task::yield_now().await;
651 FOO.with(|_f| {});
652 Err::<(), _>(format_err!("test"))
653 })
654 });
655 let result = Instance::new_async(&mut store, &module, &[func.into()]).await;
656 assert!(result.is_err());
657 })
658 .await;
659
660 assert_eq!(COUNTER.load(Ordering::SeqCst), 1);
661}
662
663#[tokio::test]
664#[cfg_attr(miri, ignore)]

Callers

nothing calls this directly

Calls 7

execute_across_threadsFunction · 0.85
yield_nowFunction · 0.85
async_storeFunction · 0.70
newFunction · 0.50
unwrapMethod · 0.45
engineMethod · 0.45
withMethod · 0.45

Tested by

no test coverage detected