1 AT_BANNER([JSON-RPC - C])
3 AT_SETUP([JSON-RPC request and successful reply])
4 AT_CHECK([test-jsonrpc --detach --pidfile="`pwd`"/pid listen punix:socket])
5 AT_CHECK([test -s pid])
6 AT_CHECK([kill -0 `cat pid`])
8 [[test-jsonrpc request unix:socket echo '[{"a": "b", "x": null}]']], [0],
9 [[{"error":null,"id":0,"result":[{"a":"b","x":null}]}
10 ]], [], [test ! -e pid || kill `cat pid`])
11 AT_CHECK([kill `cat pid`])
14 AT_SETUP([JSON-RPC request and error reply])
15 AT_CHECK([test-jsonrpc --detach --pidfile="`pwd`"/pid listen punix:socket])
16 AT_CHECK([test -s pid])
17 AT_CHECK([kill -0 `cat pid`])
19 [[test-jsonrpc request unix:socket bad-request '[]']], [0],
20 [[{"error":{"error":"unknown method"},"id":0,"result":null}
21 ]], [], [test ! -e pid || kill `cat pid`])
22 AT_CHECK([kill `cat pid`])
25 AT_SETUP([JSON-RPC notification])
26 AT_CHECK([test-jsonrpc --detach --pidfile="`pwd`"/pid listen punix:socket])
27 AT_CHECK([test -s pid])
28 # When a daemon dies it deletes its pidfile, so make a copy.
29 AT_CHECK([cp pid pid2])
30 AT_CHECK([kill -0 `cat pid2`])
31 AT_CHECK([[test-jsonrpc notify unix:socket shutdown '[]']], [0], [],
32 [], [kill `cat pid2`])
35 # First try a quick sleep, so that the test completes very quickly
36 # in the normal case. POSIX doesn't require fractional times to
37 # work, so this might not work.
38 sleep 0.1; if kill -0 $pid; then :; else echo success; exit 0; fi
39 # Then wait up to 2 seconds.
40 sleep 1; if kill -0 $pid; then :; else echo success; exit 0; fi
41 sleep 1; if kill -0 $pid; then :; else echo success; exit 0; fi
42 echo failure; exit 1], [0], [success
44 AT_CHECK([test ! -e pid])