Skip to content

Commit

Permalink
Fix publish_control in jetstream_tests
Browse files Browse the repository at this point in the history
  • Loading branch information
n1ghtmare committed Jul 25, 2023
1 parent 3d613b3 commit 8e0663b
Showing 1 changed file with 64 additions and 29 deletions.
93 changes: 64 additions & 29 deletions async-nats/tests/jetstream_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,17 @@ mod jetstream {
let info = stream.info().await.unwrap();
assert_eq!(2, info.state.messages);

context
.publish("foo".to_string(), "data".into())
.expected_last_message_id("invalid")
.await
.unwrap()
.await
.unwrap_err();
assert_eq!(
context
.publish("foo".to_string(), "data".into())
.expected_last_message_id("invalid")
.await
.unwrap()
.await
.unwrap_err()
.kind(),
PublishErrorKind::WrongLastMessageId
);

let info = stream.info().await.unwrap();
assert_eq!(2, info.state.messages);
Expand All @@ -178,6 +182,19 @@ mod jetstream {
let info = stream.info().await.unwrap();
assert_eq!(3, info.state.messages);

// 3 messages should be there, so this should error
assert_eq!(
context
.publish("foo".into(), "data".into())
.expected_last_sequence(2)
.await
.unwrap()
.await
.unwrap_err()
.kind(),
PublishErrorKind::WrongLastSequence
);

context
.publish("bar".to_string(), "data".into())
.expected_last_sequence(3)
Expand All @@ -189,38 +206,56 @@ mod jetstream {
let info = stream.info().await.unwrap();
assert_eq!(4, info.state.messages);

// 4 messages should be there, so this should error
assert_eq!(
context
.publish("foo".into(), "data".into())
.expected_last_sequence(3)
.await
.unwrap()
.await
.unwrap_err()
.kind(),
PublishErrorKind::WrongLastSequence
);

// check if it works for the other subjects in the stream.
context
.publish("foo".to_string(), "data".into())
.expected_last_subject_sequence(3)
.publish("baz".into(), "data".into())
.expected_last_subject_sequence(0)
.await
.unwrap()
.await
.unwrap();

let info = stream.info().await.unwrap();
assert_eq!(5, info.state.messages);

context
.publish("foo".to_string(), "data".into())
.expected_last_sequence(1)
.await
.unwrap()
.await
.unwrap_err();
// sequence is now 1, so this should error
assert_eq!(
context
.publish("baz".into(), "data".into())
.expected_last_subject_sequence(1)
.await
.unwrap()
.await
.unwrap_err()
.kind(),
PublishErrorKind::WrongLastSequence
);

let info = stream.info().await.unwrap();
assert_eq!(5, info.state.messages);

context
.publish("foo".to_string(), "data".into())
.expected_last_subject_sequence(1)
.await
.unwrap()
.await
.unwrap_err();

let info = stream.info().await.unwrap();
assert_eq!(5, info.state.messages);
// 5 messages should be there, so this should error
assert_eq!(
context
.publish("foo".into(), "data".into())
.expected_last_sequence(4)
.await
.unwrap()
.await
.unwrap_err()
.kind(),
PublishErrorKind::WrongLastSequence
);

let subjects = ["foo", "bar", "baz"];
for subject in subjects {
Expand Down

0 comments on commit 8e0663b

Please sign in to comment.