Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async def test_will_message(init_clients):
aclient, callback, bclient, callback2 = init_clients
# re-initialize aclient with will message
will_message = gmqtt.Message(TOPICS[2], "I'm dead finally")
aclient = gmqtt.Client(PREFIX + "myclientid3", clean_session=True, will_message=will_message)
aclient.set_auth_credentials(username)
await aclient.connect(host, port=port)
await bclient.connect(host=host, port=port)
bclient.subscribe(TOPICS[2])
await asyncio.sleep(1)
await aclient.disconnect(reason_code=4)
await asyncio.sleep(1)
assert len(callback2.messages) == 1
pub_client = gmqtt.Client("clientgonnapub")
assign_callbacks_to_client(pub_client)
pub_client.set_auth_credentials(token, None)
await pub_client.connect(broker_host, broker_port)
# this message received by sub_client will have two subscription identifiers
pub_client.publish('TEST/PROPS/42', '42 is the answer', qos=1, content_type='utf-8',
message_expiry_interval=60, user_property=('time', str(time.time())))
pub_client.publish('TEST', 'Test 42', qos=1, content_type='utf-8',
message_expiry_interval=60, user_property=('time', str(time.time())))
# just another way to publish same message
msg = gmqtt.Message('TEST/PROPS/42', '42 is the answer', qos=1, content_type='utf-8',
message_expiry_interval=60, user_property=('time', str(time.time())))
pub_client.publish(msg)
pub_client.publish('TEST/42', {42: 'is the answer'}, qos=1, content_type='json',
message_expiry_interval=60, user_property=('time', str(time.time())))
await STOP.wait()
await pub_client.disconnect()
await sub_client.disconnect(session_expiry_interval=0)