@@ -1040,3 +1040,38 @@ func Test_cleanUpMids(t *testing.T) {
1040
1040
1041
1041
c .Disconnect (250 )
1042
1042
}
1043
+
1044
+ // Test that cleanup happens properly on explicit Disconnect()
1045
+ func Test_cleanUpMids_2 (t * testing.T ) {
1046
+ ops := NewClientOptions ()
1047
+ ops .AddBroker (FVTTCP )
1048
+ ops .SetClientID ("auto_reconnect" )
1049
+ ops .SetCleanSession (true )
1050
+ ops .SetAutoReconnect (true )
1051
+ ops .SetKeepAlive (10 * time .Second )
1052
+
1053
+ c := NewClient (ops )
1054
+
1055
+ if token := c .Connect (); token .Wait () && token .Error () != nil {
1056
+ t .Fatalf ("Error on Client.Connect(): %v" , token .Error ())
1057
+ }
1058
+
1059
+ token := c .Publish ("/test/cleanUP" , 2 , false , "cleanup test 2" )
1060
+ if len (c .(* client ).messageIds .index ) == 0 {
1061
+ t .Fatalf ("Should be a token in the messageIDs, none found" )
1062
+ }
1063
+ fmt .Println ("Disconnecting" , len (c .(* client ).messageIds .index ))
1064
+ c .Disconnect (0 )
1065
+
1066
+ fmt .Println ("Wait on Token" )
1067
+ // We should be able to wait on this token without any issue
1068
+ token .Wait ()
1069
+
1070
+ if len (c .(* client ).messageIds .index ) > 0 {
1071
+ t .Fatalf ("Should have cleaned up messageIDs, have %d left" , len (c .(* client ).messageIds .index ))
1072
+ }
1073
+ if token .Error () == nil {
1074
+ t .Fatal ("token should have received an error on connection loss" )
1075
+ }
1076
+ fmt .Println (token .Error ())
1077
+ }
0 commit comments