@@ -973,6 +973,115 @@ module.exports = function (server, config) {
973
973
}
974
974
} )
975
975
976
+ it ( 'should handle error with async incoming store in QoS 2 `handlePublish` method' , function ( done ) {
977
+ function AsyncStore ( ) {
978
+ if ( ! ( this instanceof AsyncStore ) ) {
979
+ return new AsyncStore ( )
980
+ }
981
+ }
982
+ AsyncStore . prototype . put = function ( packet , cb ) {
983
+ process . nextTick ( function ( ) {
984
+ cb ( new Error ( 'Error' ) )
985
+ } )
986
+ }
987
+ var store = new AsyncStore ( )
988
+ var client = connect ( { incomingStore : store } )
989
+
990
+ client . _handlePublish ( {
991
+ messageId : 1 ,
992
+ topic : 'test' ,
993
+ payload : 'test' ,
994
+ qos : 2
995
+ } , function ( ) {
996
+ done ( )
997
+ client . end ( )
998
+ } )
999
+ } )
1000
+
1001
+ it ( 'should handle error with async incoming store in QoS 2 `handlePubrel` method' , function ( done ) {
1002
+ function AsyncStore ( ) {
1003
+ if ( ! ( this instanceof AsyncStore ) ) {
1004
+ return new AsyncStore ( )
1005
+ }
1006
+ }
1007
+ AsyncStore . prototype . put = function ( packet , cb ) {
1008
+ process . nextTick ( function ( ) {
1009
+ cb ( new Error ( 'Error' ) )
1010
+ } )
1011
+ }
1012
+ AsyncStore . prototype . get = function ( packet , cb ) {
1013
+ process . nextTick ( function ( ) {
1014
+ cb ( null , { cmd : 'publish' } )
1015
+ } )
1016
+ }
1017
+ var store = new AsyncStore ( )
1018
+ var client = connect ( { incomingStore : store } )
1019
+
1020
+ client . _handlePubrel ( {
1021
+ messageId : 1 ,
1022
+ qos : 2
1023
+ } , function ( ) {
1024
+ done ( )
1025
+ client . end ( )
1026
+ } )
1027
+ } )
1028
+
1029
+ it ( 'should handle success with async incoming store in QoS 2 `handlePubrel` method' , function ( done ) {
1030
+ var putComplete = false
1031
+ function AsyncStore ( ) {
1032
+ if ( ! ( this instanceof AsyncStore ) ) {
1033
+ return new AsyncStore ( )
1034
+ }
1035
+ }
1036
+ AsyncStore . prototype . put = function ( packet , cb ) {
1037
+ process . nextTick ( function ( ) {
1038
+ putComplete = true
1039
+ cb ( null )
1040
+ } )
1041
+ }
1042
+ AsyncStore . prototype . get = function ( packet , cb ) {
1043
+ process . nextTick ( function ( ) {
1044
+ cb ( null , { cmd : 'publish' } )
1045
+ } )
1046
+ }
1047
+ var store = new AsyncStore ( )
1048
+ var client = connect ( { incomingStore : store } )
1049
+
1050
+ client . _handlePubrel ( {
1051
+ messageId : 1 ,
1052
+ qos : 2
1053
+ } , function ( ) {
1054
+ putComplete . should . equal ( true )
1055
+ done ( )
1056
+ client . end ( )
1057
+ } )
1058
+ } )
1059
+
1060
+ it ( 'should handle error with async incoming store in QoS 1 `handlePublish` method' , function ( done ) {
1061
+ function AsyncStore ( ) {
1062
+ if ( ! ( this instanceof AsyncStore ) ) {
1063
+ return new AsyncStore ( )
1064
+ }
1065
+ }
1066
+ AsyncStore . prototype . put = function ( packet , cb ) {
1067
+ process . nextTick ( function ( ) {
1068
+ cb ( null , 'Error' )
1069
+ } )
1070
+ }
1071
+ var store = new AsyncStore ( )
1072
+ var client = connect ( { incomingStore : store } )
1073
+
1074
+ client . _handlePublish ( {
1075
+ messageId : 1 ,
1076
+ topic : 'test' ,
1077
+ payload : 'test' ,
1078
+ qos : 1
1079
+ } , function ( ) {
1080
+ done ( )
1081
+ client . end ( )
1082
+ } )
1083
+ } )
1084
+
976
1085
it ( 'should not send a `pubcomp` if the execution of `handleMessage` fails for messages with QoS `2`' , function ( done ) {
977
1086
var store = new Store ( )
978
1087
var client = connect ( { incomingStore : store } )
0 commit comments