MCPcopy Index your code
hub / github.com/endbasic/endbasic / test_exec_async_upcall_flow

Function test_exec_async_upcall_flow

core/src/vm/mod.rs:740–763  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

738
739 #[tokio::test]
740 async fn test_exec_async_upcall_flow() {
741 let data = Rc::from(RefCell::from(vec![]));
742 let mut upcalls_by_name: HashMap<SymbolKey, Rc<dyn Callable>> = HashMap::new();
743 upcalls_by_name.insert(SymbolKey::from("ASYNC_INCREMENT"), AsyncIncrementFunction::new());
744 upcalls_by_name.insert(SymbolKey::from("OUT"), OutCommand::new(data.clone()));
745
746 let compiler = Compiler::new(&upcalls_by_name, &[]).unwrap();
747 let image = compiler.compile(&mut b"OUT ASYNC_INCREMENT(123): OUT 5".as_slice()).unwrap();
748 let mut vm = Vm::new(upcalls_by_name);
749
750 match vm.exec(&image) {
751 StopReason::UpcallAsync(handler) => handler.invoke().await.unwrap(),
752 _ => panic!("Execution should stop at ASYNC_INCREMENT upcall"),
753 }
754
755 assert!(data.borrow().is_empty());
756
757 match vm.exec(&image) {
758 StopReason::Eof => (),
759 _ => panic!("Execution should stop at EOF"),
760 }
761
762 assert_eq!(["124", "5"], *data.borrow().as_slice());
763 }
764
765 #[tokio::test]
766 async fn test_exec_async_upcall_error_can_resume_after_append() {

Callers

nothing calls this directly

Calls 5

invokeMethod · 0.80
insertMethod · 0.45
compileMethod · 0.45
as_sliceMethod · 0.45
execMethod · 0.45

Tested by

no test coverage detected