summaryrefslogtreecommitdiffstats
path: root/tests/servers
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--tests/servers/invalid_json.py27
-rw-r--r--tests/servers/large_response.py36
2 files changed, 63 insertions, 0 deletions
diff --git a/tests/servers/invalid_json.py b/tests/servers/invalid_json.py
new file mode 100644
index 0000000..5b40d7a
--- /dev/null
+++ b/tests/servers/invalid_json.py
@@ -0,0 +1,27 @@
+"""This server does nothing but print invalid JSON."""
+import asyncio
+import threading
+import sys
+from concurrent.futures import ThreadPoolExecutor
+
+from pygls.server import aio_readline
+
+
+def handler(data):
+ content = 'Content-Length: 5\r\n\r\n{"ll}'.encode("utf8")
+ sys.stdout.buffer.write(content)
+ sys.stdout.flush()
+
+
+async def main():
+ await aio_readline(
+ asyncio.get_running_loop(),
+ ThreadPoolExecutor(),
+ threading.Event(),
+ sys.stdin.buffer,
+ handler,
+ )
+
+
+if __name__ == "__main__":
+ asyncio.run(main())
diff --git a/tests/servers/large_response.py b/tests/servers/large_response.py
new file mode 100644
index 0000000..fd85b62
--- /dev/null
+++ b/tests/servers/large_response.py
@@ -0,0 +1,36 @@
+"""This server returns a particuarly large response."""
+import asyncio
+import threading
+import sys
+from concurrent.futures import ThreadPoolExecutor
+
+from pygls.server import aio_readline
+
+
+def handler(data):
+ payload = dict(
+ jsonrpc="2.0",
+ id=1,
+ result=dict(
+ numbers=list(range(100_000)),
+ ),
+ )
+ content = str(payload).replace("'", '"')
+ message = f"Content-Length: {len(content)}\r\n\r\n{content}".encode("utf8")
+
+ sys.stdout.buffer.write(message)
+ sys.stdout.flush()
+
+
+async def main():
+ await aio_readline(
+ asyncio.get_running_loop(),
+ ThreadPoolExecutor(),
+ threading.Event(),
+ sys.stdin.buffer,
+ handler,
+ )
+
+
+if __name__ == "__main__":
+ asyncio.run(main())