Unverified Commit d390823a authored by Alexandru Vasile's avatar Alexandru Vasile Committed by GitHub
Browse files

server: Expose the subscription ID (#900)



* server: Expose the subscription ID

Signed-off-by: default avatarAlexandru Vasile <alexandru.vasile@parity.io>

* tests: Check subscription ID is exposed correctly

Signed-off-by: default avatarAlexandru Vasile <alexandru.vasile@parity.io>

* server: Dedicated method for exposing the sub ID

Signed-off-by: default avatarAlexandru Vasile <alexandru.vasile@parity.io>

* Fix clippy

Signed-off-by: default avatarAlexandru Vasile <alexandru.vasile@parity.io>

Signed-off-by: default avatarAlexandru Vasile <alexandru.vasile@parity.io>
parent b99e01e2
Pipeline #221249 passed with stages
in 55 minutes and 2 seconds
......@@ -873,6 +873,18 @@ impl SubscriptionSink {
}
}
/// Return the subscription ID if the the subscription was accepted.
///
/// [`SubscriptionSink::accept`] should be called prior to this method.
pub fn subscription_id(&self) -> Option<RpcSubscriptionId<'static>> {
if self.id.is_some() {
// Subscription was not accepted.
None
} else {
Some(self.uniq_sub.sub_id.clone())
}
}
/// Send a message back to subscribers.
///
/// Returns
......
......@@ -490,8 +490,7 @@ async fn can_register_modules() {
assert_eq!(mod1.method_names().count(), 2);
let err = mod1.merge(mod2).unwrap_err();
let _expected_err = Error::MethodAlreadyRegistered(String::from("bla"));
assert!(matches!(err, _expected_err));
assert!(matches!(err, Error::MethodAlreadyRegistered(err) if err == "bla"));
assert_eq!(mod1.method_names().count(), 2);
}
......@@ -548,8 +547,15 @@ async fn custom_subscription_id_works() {
let mut module = RpcModule::new(());
module
.register_subscription("subscribe_hello", "subscribe_hello", "unsubscribe_hello", |_, mut sink, _| {
// There is no subscription ID prior to calling accept.
let sub_id = sink.subscription_id();
assert!(sub_id.is_none());
sink.accept()?;
let sub_id = sink.subscription_id();
assert!(matches!(sub_id, Some(SubscriptionId::Str(id)) if id == "0xdeadbeef"));
tokio::spawn(async move {
loop {
let _ = &sink;
......
......@@ -416,7 +416,7 @@ async fn accepted_twice_subscription_without_server() {
module
.register_subscription("my_sub", "my_sub", "my_unsub", |_, mut sink, _| {
let res = sink.accept();
assert!(matches!(res, Ok(())));
assert!(matches!(res, Ok(_)));
let res = sink.accept();
assert!(matches!(res, Err(_)));
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment