@@ -29,7 +29,7 @@ def handle_subscribe(client, user_data, topic, qos):
2929 # short topic with remaining length encoded as single byte
3030 (
3131 "foo/bar" ,
32- bytearray ([0x90 , 0x03 , 0x00 , 0x01 , 0x00 ]),
32+ bytearray ([0x90 , 0x03 , 0x00 , 0x01 , 0x00 ]), # SUBACK
3333 bytearray (
3434 [
3535 0x82 , # fixed header
@@ -52,7 +52,7 @@ def handle_subscribe(client, user_data, topic, qos):
5252 # remaining length is encoded as 2 bytes due to long topic name.
5353 (
5454 "f" + "o" * 257 ,
55- bytearray ([0x90 , 0x03 , 0x00 , 0x01 , 0x00 ]),
55+ bytearray ([0x90 , 0x03 , 0x00 , 0x01 , 0x00 ]), # SUBACK
5656 bytearray (
5757 [
5858 0x82 , # fixed header
@@ -68,11 +68,58 @@ def handle_subscribe(client, user_data, topic, qos):
6868 + [0x00 ] # QoS
6969 ),
7070 ),
71+ # SUBSCRIBE responded to by PUBLISH followed by SUBACK
72+ (
73+ "foo/bar" ,
74+ bytearray (
75+ [
76+ 0x30 , # PUBLISH
77+ 0x0C ,
78+ 0x00 ,
79+ 0x07 ,
80+ 0x66 ,
81+ 0x6F ,
82+ 0x6F ,
83+ 0x2F ,
84+ 0x62 ,
85+ 0x61 ,
86+ 0x72 ,
87+ 0x66 ,
88+ 0x6F ,
89+ 0x6F ,
90+ 0x90 , # SUBACK
91+ 0x03 ,
92+ 0x00 ,
93+ 0x01 ,
94+ 0x00 ,
95+ ]
96+ ),
97+ bytearray (
98+ [
99+ 0x82 , # fixed header
100+ 0x0C , # remaining length
101+ 0x00 ,
102+ 0x01 , # message ID
103+ 0x00 ,
104+ 0x07 , # topic length
105+ 0x66 , # topic
106+ 0x6F ,
107+ 0x6F ,
108+ 0x2F ,
109+ 0x62 ,
110+ 0x61 ,
111+ 0x72 ,
112+ 0x00 , # QoS
113+ ]
114+ ),
115+ ),
71116]
72117
73118
74119@pytest .mark .parametrize (
75- "topic,to_send,exp_recv" , testdata , ids = ["short_topic" , "long_topic" ]
120+ "topic,to_send,exp_recv" ,
121+ testdata ,
122+ ids = ["short_topic" , "long_topic" , "publish_first" ],
76123)
77124def test_subscribe (topic , to_send , exp_recv ) -> None :
78125 """
0 commit comments