]> git.proxmox.com Git - ovs.git/blame - tests/jsonrpc.at
datapath: Fix off-by-one error in dev_get_stats() compat code.
[ovs.git] / tests / jsonrpc.at
CommitLineData
99155935 1AT_BANNER([JSON-RPC - C])
f2129093
BP
2
3AT_SETUP([JSON-RPC request and successful reply])
4AT_CHECK([test-jsonrpc --detach --pidfile=$PWD/pid listen punix:socket])
5AT_CHECK([test -s pid])
6AT_CHECK([kill -0 `cat pid`])
7AT_CHECK(
8 [[test-jsonrpc request unix:socket echo '[{"a": "b", "x": null}]']], [0],
9 [[{"error":null,"id":0,"result":[{"a":"b","x":null}]}
10]], [ignore], [test ! -e pid || kill `cat pid`])
11AT_CHECK([kill `cat pid`])
12AT_CLEANUP
13
14AT_SETUP([JSON-RPC request and error reply])
15AT_CHECK([test-jsonrpc --detach --pidfile=$PWD/pid listen punix:socket])
16AT_CHECK([test -s pid])
17AT_CHECK([kill -0 `cat pid`])
18AT_CHECK(
19 [[test-jsonrpc request unix:socket bad-request '[]']], [0],
20 [[{"error":{"error":"unknown method"},"id":0,"result":null}
21]], [ignore], [test ! -e pid || kill `cat pid`])
22AT_CHECK([kill `cat pid`])
23AT_CLEANUP
24
25AT_SETUP([JSON-RPC notification])
26AT_CHECK([test-jsonrpc --detach --pidfile=$PWD/pid listen punix:socket])
27AT_CHECK([test -s pid])
28# When a daemon dies it deletes its pidfile, so make a copy.
29AT_CHECK([cp pid pid2])
30AT_CHECK([kill -0 `cat pid2`])
7c126fbb 31AT_CHECK([[test-jsonrpc notify unix:socket shutdown '[]']], [0], [],
f2129093
BP
32 [ignore], [kill `cat pid2`])
33AT_CHECK(
34 [pid=`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
43], [ignore])
44AT_CHECK([test ! -e pid])
45AT_CLEANUP