shamblett / mqtt5_client

A server and browser based MQTT 5 client for dart
Other
51 stars 29 forks source link

Unsubscribe doesn't change value of subscriptionTopicStatus #26

Closed Simonovsky closed 2 years ago

Simonovsky commented 2 years ago

Hello again,

When I unsubscribe from topics value of subscriptionTopicStatus stays pending before unsubAck and after unsubscribeAck message changes back to active. Am I doing something wrong or is this a bug?

I've reused test from issue #22 for it:

import 'package:mqtt5_client/mqtt5_client.dart';
import 'package:mqtt5_client/mqtt5_server_client.dart';
import 'package:typed_data/typed_buffers.dart';
import 'package:test/test.dart';

Future<int> main() async {
  resubscribeAfterUnsubscribe(String broker_url, int port, bool useWs, int delay) async {
    final client = MqttServerClient(broker_url, "");
    client.useWebSocket = useWs;
    client.port = port;
    client.logging(on: true);

    String topic = "iWantToBeUnsubscribed";
    var sendData = Uint8Buffer();

    await client.connect();

    client.subscribe(topic, MqttQos.exactlyOnce);

    print("Waiting for $delay seconds before unsubscribing");
    await MqttUtilities.asyncSleep(delay);

    client.unsubscribeStringTopic(topic);

    print("Waiting for $delay seconds after unsubscribing");
    await MqttUtilities.asyncSleep(delay);

    var subStatus = client.subscriptionsManager!.getSubscriptionTopicStatus(topic);
    print(subStatus);

    expect(subStatus, MqttSubscriptionStatus.doesNotExist);

    client.disconnect();

  }

  test("[broker.emqx.io] websocket unsubscribe", () => resubscribeAfterUnsubscribe("ws://broker.emqx.io/mqtt", 8083, true, 0));

  test("[broker.emqx.io] websocket unsubscribe after a delay", () => resubscribeAfterUnsubscribe("ws://broker.emqx.io/mqtt", 8083, true, 5));

  test("[broker.hivemq.com] websocket unsubscribe right after its published", () =>
      resubscribeAfterUnsubscribe("ws://broker.hivemq.com/mqtt", 8000, true, 0));

  test("[broker.hivemq.com] websocket unsubscribe after a delay", () => resubscribeAfterUnsubscribe("ws://broker.hivemq.com/mqtt", 8000, true, 5));

  return 0;
}

image

shamblett commented 2 years ago

Your output above shows it stays at pending, not active however it should not exist after a successful unsubscribe, on the face of this looks like a bug

shamblett commented 2 years ago

Yes confirmed this, I've pushed the fix into master, both the 'after delay' tests work now.