Skip to content

Commit

Permalink
update subscription index&filter
Browse files Browse the repository at this point in the history
  • Loading branch information
xiazhvera committed Nov 24, 2023
1 parent d09633a commit a6c78b0
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions canary/mqtt5/canary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,21 +121,20 @@ async function doSubscribe(context: CanaryContext) {
]
});

context.subscriptions[index].push(topicFilter);
context.mqttStats.subscribesSucceeded++;
} catch (err) {
context.mqttStats.subscribesFailed++;
if(context.subscriptions[index].length > 0 )
context.subscriptions[index].filter(entry => entry !== topicFilter);
return;
}

context.subscriptions[index].push(topicFilter);
context.mqttStats.subscribesSucceeded++;
}

async function doUnsubscribe(context: CanaryContext) {
let index = getRandomIndex(context.clients);
if (context.subscriptions.length == 0) {
return;
}

let index = getRandomIndex(context.clients);
let topicFilter: string = context.subscriptions[index].pop() ?? "canthappen";

try {
Expand Down

0 comments on commit a6c78b0

Please sign in to comment.