summaryrefslogtreecommitdiff
path: root/tests/jsonrpc.at
blob: e06b5b6366028a5f89244fc19d00c6a5a16f65de (plain)
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
AT_BANNER([JSON-RPC - C])

AT_SETUP([JSON-RPC request and successful reply])
OVS_RUNDIR=`pwd`; export OVS_RUNDIR
AT_CHECK([ovstest test-jsonrpc --detach --no-chdir --pidfile="`pwd`"/pid listen punix:socket])
AT_CHECK([test -s pid])
AT_CHECK([kill -0 `cat pid`])
AT_CHECK(
  [[ovstest test-jsonrpc request unix:socket echo '[{"a": "b", "x": null}]']], [0],
  [[{"error":null,"id":0,"result":[{"a":"b","x":null}]}
]], [], [test ! -e pid || kill `cat pid`])
AT_CHECK([kill `cat pid`])
AT_CLEANUP

AT_SETUP([JSON-RPC request and error reply])
OVS_RUNDIR=`pwd`; export OVS_RUNDIR
AT_CHECK([ovstest test-jsonrpc --detach --no-chdir --pidfile="`pwd`"/pid listen punix:socket])
AT_CHECK([test -s pid])
AT_CHECK([kill -0 `cat pid`])
AT_CHECK(
  [[ovstest test-jsonrpc request unix:socket bad-request '[]']], [0],
  [[{"error":{"error":"unknown method"},"id":0,"result":null}
]], [], [test ! -e pid || kill `cat pid`])
AT_CHECK([kill `cat pid`])
AT_CLEANUP

AT_SETUP([JSON-RPC notification])
OVS_RUNDIR=`pwd`; export OVS_RUNDIR
AT_CHECK([ovstest test-jsonrpc --detach --no-chdir --pidfile="`pwd`"/pid listen punix:socket])
AT_CHECK([test -s pid])
# When a daemon dies it deletes its pidfile, so make a copy.
AT_CHECK([cp pid pid2])
AT_CHECK([kill -0 `cat pid2`])
AT_CHECK([[ovstest test-jsonrpc notify unix:socket shutdown '[]']], [0], [],
  [], [kill `cat pid2`])
AT_CHECK(
  [pid=`cat pid2`
   # First try a quick sleep, so that the test completes very quickly
   # in the normal case.  POSIX doesn't require fractional times to
   # work, so this might not work.
   sleep 0.1; if kill -0 $pid; then :; else echo success; exit 0; fi
   # Then wait up to 2 seconds.
   sleep 1; if kill -0 $pid; then :; else echo success; exit 0; fi
   sleep 1; if kill -0 $pid; then :; else echo success; exit 0; fi
   echo failure; exit 1], [0], [success
], [ignore])
AT_CHECK([test ! -e pid])
AT_CLEANUP