mirror of
https://github.com/logos-messaging/logos-messaging-nim.git
synced 2026-01-07 00:13:06 +00:00
chore: don't return error on double relay subscription/unsubscription (#3429)
This commit is contained in:
parent
768b2785e1
commit
5e22ea18b6
@ -631,7 +631,7 @@ suite "WakuNode - Relay":
|
|||||||
# Stop all nodes
|
# Stop all nodes
|
||||||
await allFutures(nodes.mapIt(it.stop()))
|
await allFutures(nodes.mapIt(it.stop()))
|
||||||
|
|
||||||
asyncTest "Only one subscription is allowed for contenttopics that generate the same shard":
|
asyncTest "Multiple subscription calls are allowed for contenttopics that generate the same shard":
|
||||||
## Setup
|
## Setup
|
||||||
let
|
let
|
||||||
nodeKey = generateSecp256k1Key()
|
nodeKey = generateSecp256k1Key()
|
||||||
@ -663,12 +663,12 @@ suite "WakuNode - Relay":
|
|||||||
## When
|
## When
|
||||||
node.subscribe((kind: ContentSub, topic: contentTopicA), some(handler)).isOkOr:
|
node.subscribe((kind: ContentSub, topic: contentTopicA), some(handler)).isOkOr:
|
||||||
assert false, "Failed to subscribe to topic: " & $error
|
assert false, "Failed to subscribe to topic: " & $error
|
||||||
node.subscribe((kind: ContentSub, topic: contentTopicB), some(handler)).isErrOr:
|
node.subscribe((kind: ContentSub, topic: contentTopicB), some(handler)).isOkOr:
|
||||||
assert false,
|
assert false,
|
||||||
"The subscription should fail because is already subscribe to that shard"
|
"The subscription call shouldn't error even though it's already subscribed to that shard"
|
||||||
node.subscribe((kind: ContentSub, topic: contentTopicC), some(handler)).isErrOr:
|
node.subscribe((kind: ContentSub, topic: contentTopicC), some(handler)).isOkOr:
|
||||||
assert false,
|
assert false,
|
||||||
"The subscription should fail because is already subscribe to that shard"
|
"The subscription call shouldn't error even though it's already subscribed to that shard"
|
||||||
|
|
||||||
## Then
|
## Then
|
||||||
node.unsubscribe((kind: ContentUnsub, topic: contentTopicB)).isOkOr:
|
node.unsubscribe((kind: ContentUnsub, topic: contentTopicB)).isOkOr:
|
||||||
|
|||||||
@ -323,12 +323,12 @@ proc subscribe*(
|
|||||||
return err("Unsupported subscription type in relay subscribe")
|
return err("Unsupported subscription type in relay subscribe")
|
||||||
|
|
||||||
if node.wakuRelay.isSubscribed(pubsubTopic):
|
if node.wakuRelay.isSubscribed(pubsubTopic):
|
||||||
debug "already subscribed to topic", pubsubTopic
|
warn "No-effect API call to subscribe. Already subscribed to topic", pubsubTopic
|
||||||
return err("Already subscribed to topic: " & $pubsubTopic)
|
return ok()
|
||||||
|
|
||||||
if contentTopicOp.isSome() and node.contentTopicHandlers.hasKey(contentTopicOp.get()):
|
if contentTopicOp.isSome() and node.contentTopicHandlers.hasKey(contentTopicOp.get()):
|
||||||
error "Invalid API call to `subscribe`. Was already subscribed"
|
warn "No-effect API call to `subscribe`. Was already subscribed"
|
||||||
return err("Invalid API call to `subscribe`. Was already subscribed")
|
return ok()
|
||||||
|
|
||||||
node.topicSubscriptionQueue.emit((kind: PubsubSub, topic: pubsubTopic))
|
node.topicSubscriptionQueue.emit((kind: PubsubSub, topic: pubsubTopic))
|
||||||
node.registerRelayDefaultHandler(pubsubTopic)
|
node.registerRelayDefaultHandler(pubsubTopic)
|
||||||
@ -364,9 +364,8 @@ proc unsubscribe*(
|
|||||||
return err("Unsupported subscription type in relay unsubscribe")
|
return err("Unsupported subscription type in relay unsubscribe")
|
||||||
|
|
||||||
if not node.wakuRelay.isSubscribed(pubsubTopic):
|
if not node.wakuRelay.isSubscribed(pubsubTopic):
|
||||||
error "Invalid API call to `unsubscribe`. Was not subscribed", pubsubTopic
|
warn "No-effect API call to `unsubscribe`. Was not subscribed", pubsubTopic
|
||||||
return
|
return ok()
|
||||||
err("Invalid API call to `unsubscribe`. Was not subscribed to: " & $pubsubTopic)
|
|
||||||
|
|
||||||
if contentTopicOp.isSome():
|
if contentTopicOp.isSome():
|
||||||
# Remove this handler only
|
# Remove this handler only
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user