Dever v0.0.2
This commit is contained in:
commit
e6e175ebcf
816 files changed
+120349
No files matched your search
@@ -0,0 +1,44 @@
|
||||
@allocation_counter@
|
||||
use dever_runtime::task::{self, RunError};
|
||||
assert_eq!(task::run(true, 8, async |scope| @main@(scope).await).unwrap().unwrap(), 42);
|
||||
assert_eq!(task::run(true, 8, async |scope| @together@(scope).await).unwrap().unwrap(), 42);
|
||||
assert_eq!(task::run(true, 8, async |scope| Ok::<_, ()>(@text@(scope, "hello".into()).await)).unwrap().unwrap(), 10);
|
||||
assert_eq!(task::run(true, 8, async |scope| Ok::<_, ()>(@borrowed@(scope, "hello".into()).await)).unwrap().unwrap(), 5);
|
||||
assert_eq!(task::run(true, 8, async |scope| Ok::<_, ()>(@multiple@(scope, 20).await)).unwrap().unwrap(), 41);
|
||||
task::run(true, 8, async |scope| @cancel@(scope).await).unwrap().unwrap();
|
||||
assert_eq!(task::run(true, 8, async |scope| Ok::<_, ()>(@captured@(scope, -1).await)).unwrap().unwrap(), -1);
|
||||
assert_eq!(task::run(true, 8, async |scope| Ok::<_, ()>(@captured@(scope, 0).await)).unwrap().unwrap(), 10);
|
||||
// 容量为 1,恢复后能再次派生,证明捕获边界已归还前一次任务的许可。
|
||||
task::run(true, 1, async |scope| {
|
||||
assert_eq!(@recovered@(scope, -1).await, -1);
|
||||
assert_eq!(@recovered@(scope, -1).await, -1);
|
||||
Ok::<_, ()>(())
|
||||
}).unwrap().unwrap();
|
||||
assert!(matches!(task::run(true, 8, async |scope| @failStop@(scope, -1).await).unwrap(), Err(RunError::Business { .. })));
|
||||
match task::run(true, 8, async |scope| Ok::<_, ()>(@overflow@(scope, i64::MAX).await)).unwrap() {
|
||||
Err(RunError::Fault { primary, additional }) => {
|
||||
let info = primary.downcast_ref::<&'static FaultInfo>().unwrap();
|
||||
assert_eq!(info.source, @source_path@);
|
||||
assert!(additional.is_empty());
|
||||
}
|
||||
_ => panic!("expected original arithmetic fault"),
|
||||
}
|
||||
|
||||
assert_eq!(task::run(true, 8, async |scope| Ok::<_, ()>(@spawnedRecovery@(scope).await)).unwrap().unwrap(), -1);
|
||||
assert_eq!(task::run(true, 8, async |scope| @handled@(scope).await).unwrap().unwrap(), 42);
|
||||
|
||||
assert!(matches!(task::run(true, 8, async |scope| @neverReturns@(scope).await).unwrap(), Err(RunError::Business { .. })));
|
||||
assert!(matches!(task::run(true, 8, async |scope| @argumentFailure@(scope, 0).await).unwrap(), Err(RunError::Business { .. })));
|
||||
task::run(true, 1, async |scope| {
|
||||
assert_eq!(@recoveredGroup@(scope, -1).await, -1);
|
||||
assert_eq!(@recoveredGroup@(scope, -1).await, -1);
|
||||
Ok::<_, ()>(())
|
||||
}).unwrap().unwrap();
|
||||
|
||||
match task::run(true, 8, async |scope| @abandonedFault@(scope, i64::MAX).await).unwrap() {
|
||||
Err(RunError::Business { additional, .. }) => {
|
||||
assert_eq!(additional.len(), 1, "unconsumed Task must stay alive until failure exit");
|
||||
assert_eq!(additional[0].downcast_ref::<&'static FaultInfo>().unwrap().source, @source_path@);
|
||||
}
|
||||
_ => panic!("primary business error must be retained"),
|
||||
}
|
||||
Reference in new issue
Block a user