Skip to content

Commit 5c7114e

Browse files
committed
add get_value test case
Signed-off-by: tison <[email protected]>
1 parent 2091fa7 commit 5c7114e

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

tokio/tests/task_local.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,3 +145,27 @@ async fn poll_after_take_value_should_fail() {
145145
// Poll the future after `take_value` has been called
146146
fut.await;
147147
}
148+
149+
#[tokio::test]
150+
async fn get_value() {
151+
tokio::task_local! {
152+
static KEY: u32
153+
}
154+
155+
KEY.scope(1, async {
156+
assert_eq!(KEY.get(), 1);
157+
assert_eq!(KEY.try_get().unwrap(), 1);
158+
})
159+
.await;
160+
161+
let fut = KEY.scope(1, async {
162+
let result = KEY.try_get();
163+
// The task local value no longer exists.
164+
assert!(result.is_err());
165+
});
166+
let mut fut = Box::pin(fut);
167+
fut.as_mut().take_value();
168+
169+
// Poll the future after `take_value` has been called
170+
fut.await;
171+
}

0 commit comments

Comments
 (0)