Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/score precision #26

Merged
merged 2 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ lazy_static! {
Script::new(include_str!("./redis-scripts/receiveMessage.lua"));
}

static JS_COMPAT_MAX_TIME_MILLIS: u64 = 9_999_999_000;
const JS_COMPAT_MAX_TIME_MILLIS: u64 = 9_999_999_000;

/// The main object of this library. Creates/Handles the redis connection and contains all the methods
#[derive(Clone)]
Expand Down Expand Up @@ -212,7 +212,7 @@ impl<T: ConnectionLike> RsmqFunctions<T> {
.arg(&key)
.cmd("ZCOUNT")
.arg(&key)
.arg(time.0)
.arg(time.0 * 1000)
.arg("+inf")
.query_async(conn)
.await?;
Expand Down Expand Up @@ -470,7 +470,7 @@ impl<T: ConnectionLike> RsmqFunctions<T> {
.query_async(conn)
.await?;

let time_millis = (result.1).0 * 1000;
let time_micros = (result.1).0 * 1000000 + (result.1).1;

let (hmget_first, hmget_second, hmget_third) =
match (result.0.first(), result.0.get(1), result.0.get(2)) {
Expand All @@ -479,7 +479,7 @@ impl<T: ConnectionLike> RsmqFunctions<T> {
};

let quid = if uid {
Some(radix_36(time_millis).to_string() + &RsmqFunctions::<T>::make_id(22)?)
Some(radix_36(time_micros).to_string() + &RsmqFunctions::<T>::make_id(22)?)
} else {
None
};
Expand All @@ -494,7 +494,7 @@ impl<T: ConnectionLike> RsmqFunctions<T> {
maxsize: hmget_third
.parse()
.map_err(|_| RsmqError::CannotParseMaxsize)?,
ts: time_millis,
ts: time_micros / 1000,
uid: quid,
})
}
Expand Down
37 changes: 37 additions & 0 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -447,3 +447,40 @@ fn change_queue_size() {
assert_eq!(attributes.maxsize, -1);
})
}

#[test]
fn sent_messages_must_keep_order() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the above changes are reverted this will fail

let rt = tokio::runtime::Runtime::new().unwrap();

rt.block_on(async move {
let ctx = TestContext::new();
let connection = ctx.async_connection().await.unwrap();
let mut rsmq = Rsmq::new_with_connection(connection, false, None);

rsmq.create_queue("queue1", None, None, None).await.unwrap();

for i in 0..10000 {
rsmq.send_message("queue1", format!("testmessage{}", i), None)
.await
.unwrap();
}

for i in 0..10000 {
let message = rsmq
.receive_message::<String>("queue1", None)
.await
.unwrap().unwrap();
assert_eq!(message.message, format!("testmessage{}", i));

rsmq.delete_message("queue1", &message.id).await.unwrap();
}

let message = rsmq
.receive_message::<String>("queue1", None)
.await
.unwrap();

assert!(message.is_none());
rsmq.delete_queue("queue1").await.unwrap();
})
}
Loading