diff options
author | Ben Pfaff <blp@nicira.com> | 2009-10-26 15:04:05 -0700 |
---|---|---|
committer | Ben Pfaff <blp@nicira.com> | 2009-11-04 15:24:40 -0800 |
commit | f212909325be9bc7e296e1a32e2fc89694a0049f (patch) | |
tree | 27bc021a3aa57d60fc62a2d8bd94257cc01cfa4f /tests/jsonrpc.at | |
parent | 1c617a495fdc6bb91e29bf00df4c837f63d63199 (diff) | |
download | openvswitch-f212909325be9bc7e296e1a32e2fc89694a0049f.tar.gz |
Implement JSON-RPC protocol.
Diffstat (limited to 'tests/jsonrpc.at')
-rw-r--r-- | tests/jsonrpc.at | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/tests/jsonrpc.at b/tests/jsonrpc.at new file mode 100644 index 000000000..d5ebf948a --- /dev/null +++ b/tests/jsonrpc.at @@ -0,0 +1,45 @@ +AT_BANNER([JSON-RPC]) + +AT_SETUP([JSON-RPC request and successful reply]) +AT_CHECK([test-jsonrpc --detach --pidfile=$PWD/pid listen punix:socket]) +AT_CHECK([test -s pid]) +AT_CHECK([kill -0 `cat pid`]) +AT_CHECK( + [[test-jsonrpc request unix:socket echo '[{"a": "b", "x": null}]']], [0], + [[{"error":null,"id":0,"result":[{"a":"b","x":null}]} +]], [ignore], [test ! -e pid || kill `cat pid`]) +AT_CHECK([kill `cat pid`]) +AT_CLEANUP + +AT_SETUP([JSON-RPC request and error reply]) +AT_CHECK([test-jsonrpc --detach --pidfile=$PWD/pid listen punix:socket]) +AT_CHECK([test -s pid]) +AT_CHECK([kill -0 `cat pid`]) +AT_CHECK( + [[test-jsonrpc request unix:socket bad-request '[]']], [0], + [[{"error":{"error":"unknown method"},"id":0,"result":null} +]], [ignore], [test ! -e pid || kill `cat pid`]) +AT_CHECK([kill `cat pid`]) +AT_CLEANUP + +AT_SETUP([JSON-RPC notification]) +AT_CHECK([test-jsonrpc --detach --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`]) +OVS_CHECK_LCOV([[test-jsonrpc notify unix:socket shutdown '[]']], [0], [], + [ignore], [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 |