File: 01-connect-575314.py

package info (click to toggle)
mosquitto 2.0.11-1%2Bdeb11u1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 6,600 kB
  • sloc: ansic: 49,265; python: 14,781; xml: 7,055; makefile: 1,756; cpp: 1,542; sh: 267; perl: 70
file content (49 lines) | stat: -rwxr-xr-x 1,647 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env python3

# Check for performance of processing user-property on CONNECT

from mosq_test_helper import *

def do_test():
    rc = 1
    props = mqtt5_props.gen_string_pair_prop(mqtt5_props.PROP_USER_PROPERTY, "key", "value")
    for i in range(0, 20000):
        props += mqtt5_props.gen_string_pair_prop(mqtt5_props.PROP_USER_PROPERTY, "key", "value")
    connect_packet_slow = mosq_test.gen_connect("connect-user-property", proto_ver=5, properties=props)
    connect_packet_fast = mosq_test.gen_connect("a"*65000, proto_ver=5)
    connack_packet = mosq_test.gen_connack(rc=0, proto_ver=5)

    port = mosq_test.get_port()
    broker = mosq_test.start_broker(filename=os.path.basename(__file__), port=port)

    try:
        t_start = time.monotonic()
        sock = mosq_test.do_client_connect(connect_packet_slow, connack_packet, port=port)
        t_stop = time.monotonic()
        sock.close()

        t_diff_slow = t_stop - t_start

        t_start = time.monotonic()
        sock = mosq_test.do_client_connect(connect_packet_fast, connack_packet, port=port)
        t_stop = time.monotonic()
        sock.close()

        t_diff_fast = t_stop - t_start
        # 20 is chosen as a factor that works in plain mode and running under
        # valgrind. The slow performance manifests as a factor of >100. Fast is <10.
        if t_diff_slow / t_diff_fast < 20:
            rc = 0
    except mosq_test.TestError:
        pass
    finally:
        broker.terminate()
        broker.wait()
        (stdo, stde) = broker.communicate()
        if rc:
            print(stde.decode('utf-8'))
            exit(rc)


do_test()
exit(0)