Return counter value from counter_incr function

This commit is contained in:
mdecimus
2024-02-21 13:07:10 +01:00
parent 75bb02d13a
commit be7c4cca73
7 changed files with 47 additions and 31 deletions

View File

@@ -434,15 +434,13 @@ fn parse_code_redirect(uri: String, state: &str) -> String {
fn unwrap_token_response(response: TokenResponse) -> (String, Option<String>, u64) {
match response {
TokenResponse::Granted {
access_token,
token_type,
expires_in,
refresh_token,
..
} => {
assert_eq!(token_type, "bearer");
(access_token, refresh_token, expires_in)
TokenResponse::Granted(granted) => {
assert_eq!(granted.token_type, "bearer");
(
granted.access_token,
granted.refresh_token,
granted.expires_in,
)
}
TokenResponse::Error { error } => panic!("Expected granted, got {:?}", error),
}

View File

@@ -179,7 +179,7 @@ async fn lookup_sql() {
"counter_get('sql', 'county') + '-' + counter_incr('sql', 'county', 1) + '-' ",
"+ counter_incr('sql', 'county', 1) + '-' + counter_get('sql', 'county')"
),
"0-0-0-2",
"0-1-2-2",
),
] {
let e = Expression::parse("test", expr, |name| {

View File

@@ -82,16 +82,28 @@ pub async fn lookup_tests() {
// Test counter
let key = "abc".as_bytes().to_vec();
store.counter_incr(key.clone(), 1, None).await.unwrap();
store
.counter_incr(key.clone(), 1, None, false)
.await
.unwrap();
assert_eq!(1, store.counter_get(key.clone()).await.unwrap());
store.counter_incr(key.clone(), 2, None).await.unwrap();
store
.counter_incr(key.clone(), 2, None, false)
.await
.unwrap();
assert_eq!(3, store.counter_get(key.clone()).await.unwrap());
store.counter_incr(key.clone(), -3, None).await.unwrap();
store
.counter_incr(key.clone(), -3, None, false)
.await
.unwrap();
assert_eq!(0, store.counter_get(key.clone()).await.unwrap());
// Test counter expiry
let key = "fgh".as_bytes().to_vec();
store.counter_incr(key.clone(), 1, 1.into()).await.unwrap();
store
.counter_incr(key.clone(), 1, 1.into(), false)
.await
.unwrap();
assert_eq!(1, store.counter_get(key.clone()).await.unwrap());
tokio::time::sleep(tokio::time::Duration::from_secs(1)).await;
store.purge_expired().await.unwrap();