core-lightning/contrib/plugins/fail/failtimeout.py
Christian Decker f5a3f1f0a2 plugin: Add a test for timeout and broken manifest
Both of these plugins will fail in interesting ways, and we should
still handle them correctly.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-12-05 23:15:59 +00:00

59 lines
1.2 KiB
Python
Executable File

#!/usr/bin/env python3
"""An example plugin that fails to answer to `getmanifest`
Used to test the `getmanifest` timeout.
"""
import json
import sys
import time
def json_getmanifest(request):
# Timeout is 10 seconds, so wait 11
time.sleep(11)
return {
"options": [
],
"rpcmethods": [
]
}
methods = {
'getmanifest': json_getmanifest,
}
partial = ""
for l in sys.stdin:
try:
partial += l
request = json.loads(partial)
except Exception:
continue
result = None
method = methods[request['method']]
params = request['params']
try:
if isinstance(params, dict):
result = method(request, **params)
else:
result = method(request, *params)
result = {
"jsonrpc": "2.0",
"result": result,
"id": request['id']
}
except Exception as e:
result = {
"jsonrpc": "2.0",
"error": "Error while processing {}".format(request['method']),
"id": request['id']
}
json.dump(result, fp=sys.stdout)
sys.stdout.write('\n')
sys.stdout.flush()
partial = ""