]>
Commit | Line | Data |
---|---|---|
36a7eb68 JH |
1 | #!/bin/sh |
2 | ||
3 | test_description='simple command server' | |
4 | ||
fdc8f79f | 5 | TEST_PASSES_SANITIZE_LEAK=true |
36a7eb68 JH |
6 | . ./test-lib.sh |
7 | ||
8 | test-tool simple-ipc SUPPORTS_SIMPLE_IPC || { | |
9 | skip_all='simple IPC not supported on this platform' | |
10 | test_done | |
11 | } | |
12 | ||
13 | stop_simple_IPC_server () { | |
14 | test-tool simple-ipc stop-daemon | |
15 | } | |
16 | ||
17 | test_expect_success 'start simple command server' ' | |
18 | test_atexit stop_simple_IPC_server && | |
19 | test-tool simple-ipc start-daemon --threads=8 && | |
20 | test-tool simple-ipc is-active | |
21 | ' | |
22 | ||
23 | test_expect_success 'simple command server' ' | |
24 | test-tool simple-ipc send --token=ping >actual && | |
25 | echo pong >expect && | |
26 | test_cmp expect actual | |
27 | ' | |
28 | ||
29 | test_expect_success 'servers cannot share the same path' ' | |
30 | test_must_fail test-tool simple-ipc run-daemon && | |
31 | test-tool simple-ipc is-active | |
32 | ' | |
33 | ||
34 | test_expect_success 'big response' ' | |
35 | test-tool simple-ipc send --token=big >actual && | |
36 | test_line_count -ge 10000 actual && | |
37 | grep -q "big: [0]*9999\$" actual | |
38 | ' | |
39 | ||
40 | test_expect_success 'chunk response' ' | |
41 | test-tool simple-ipc send --token=chunk >actual && | |
42 | test_line_count -ge 10000 actual && | |
43 | grep -q "big: [0]*9999\$" actual | |
44 | ' | |
45 | ||
46 | test_expect_success 'slow response' ' | |
47 | test-tool simple-ipc send --token=slow >actual && | |
48 | test_line_count -ge 100 actual && | |
49 | grep -q "big: [0]*99\$" actual | |
50 | ' | |
51 | ||
52 | # Send an IPC with n=100,000 bytes of ballast. This should be large enough | |
53 | # to force both the kernel and the pkt-line layer to chunk the message to the | |
54 | # daemon and for the daemon to receive it in chunks. | |
55 | # | |
56 | test_expect_success 'sendbytes' ' | |
57 | test-tool simple-ipc sendbytes --bytecount=100000 --byte=A >actual && | |
58 | grep "sent:A00100000 rcvd:A00100000" actual | |
59 | ' | |
60 | ||
61 | # Start a series of <threads> client threads that each make <batchsize> | |
62 | # IPC requests to the server. Each (<threads> * <batchsize>) request | |
63 | # will open a new connection to the server and randomly bind to a server | |
64 | # thread. Each client thread exits after completing its batch. So the | |
65 | # total number of live client threads will be smaller than the total. | |
66 | # Each request will send a message containing at least <bytecount> bytes | |
67 | # of ballast. (Responses are small.) | |
68 | # | |
69 | # The purpose here is to test threading in the server and responding to | |
70 | # many concurrent client requests (regardless of whether they come from | |
71 | # 1 client process or many). And to test that the server side of the | |
72 | # named pipe/socket is stable. (On Windows this means that the server | |
73 | # pipe is properly recycled.) | |
74 | # | |
75 | # On Windows it also lets us adjust the connection timeout in the | |
76 | # `ipc_client_send_command()`. | |
77 | # | |
78 | # Note it is easy to drive the system into failure by requesting an | |
79 | # insane number of threads on client or server and/or increasing the | |
80 | # per-thread batchsize or the per-request bytecount (ballast). | |
81 | # On Windows these failures look like "pipe is busy" errors. | |
82 | # So I've chosen fairly conservative values for now. | |
83 | # | |
84 | # We expect output of the form "sent:<letter><length> ..." | |
85 | # With terms (7, 19, 13) we expect: | |
86 | # <letter> in [A-G] | |
87 | # <length> in [19+0 .. 19+(13-1)] | |
88 | # and (7 * 13) successful responses. | |
89 | # | |
90 | test_expect_success 'stress test threads' ' | |
91 | test-tool simple-ipc multiple \ | |
92 | --threads=7 \ | |
93 | --bytecount=19 \ | |
94 | --batchsize=13 \ | |
95 | >actual && | |
96 | test_line_count = 92 actual && | |
97 | grep "good 91" actual && | |
98 | grep "sent:A" <actual >actual_a && | |
99 | cat >expect_a <<-EOF && | |
100 | sent:A00000019 rcvd:A00000019 | |
101 | sent:A00000020 rcvd:A00000020 | |
102 | sent:A00000021 rcvd:A00000021 | |
103 | sent:A00000022 rcvd:A00000022 | |
104 | sent:A00000023 rcvd:A00000023 | |
105 | sent:A00000024 rcvd:A00000024 | |
106 | sent:A00000025 rcvd:A00000025 | |
107 | sent:A00000026 rcvd:A00000026 | |
108 | sent:A00000027 rcvd:A00000027 | |
109 | sent:A00000028 rcvd:A00000028 | |
110 | sent:A00000029 rcvd:A00000029 | |
111 | sent:A00000030 rcvd:A00000030 | |
112 | sent:A00000031 rcvd:A00000031 | |
113 | EOF | |
114 | test_cmp expect_a actual_a | |
115 | ' | |
116 | ||
117 | test_expect_success 'stop-daemon works' ' | |
118 | test-tool simple-ipc stop-daemon && | |
119 | test_must_fail test-tool simple-ipc is-active && | |
120 | test_must_fail test-tool simple-ipc send --token=ping | |
121 | ' | |
122 | ||
123 | test_done |