summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichele Simionato <michele.simionato@gmail.com>2010-08-01 07:14:54 +0200
committerMichele Simionato <michele.simionato@gmail.com>2010-08-01 07:14:54 +0200
commit5b08a4da7625622a072d78edc6254185be453b3d (patch)
tree87702c3b1e7c883c50a731d0ccdac30b8fa1d5f2
parentf434a4f365403c7226a08324082bc0d4497d82ae (diff)
downloadmicheles-5b08a4da7625622a072d78edc6254185be453b3d.tar.gz
Fixed the text for the plac server
-rw-r--r--plac/doc/test_server.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/plac/doc/test_server.py b/plac/doc/test_server.py
new file mode 100644
index 0000000..5567f40
--- /dev/null
+++ b/plac/doc/test_server.py
@@ -0,0 +1,34 @@
+import multiprocessing, subprocess, time, random
+import plac
+from ishelve2 import ShelveInterface
+
+i = plac.Interpreter(ShelveInterface())
+
+COMMANDS = ['''\
+.help
+set a 1
+''',
+'''\
+set b 1
+showall
+''']
+
+def client_send(commands, port):
+ time.sleep(.5) # wait a bit for the server to start
+ po = subprocess.Popen(['telnet', 'localhost', str(port)],
+ stdin=subprocess.PIPE)
+ for cmd in commands.splitlines():
+ po.stdin.write(cmd + '\n')
+ time.sleep(.1) # wait a bit for the server to answer
+
+def test():
+ port = random.choice(range(2000, 20000))
+ clients = []
+ for cmds in COMMANDS:
+ cl = multiprocessing.Process(target=client_send, args=(cmds, port))
+ clients.append(cl)
+ cl.start()
+ i.stop_server(wait=1)
+ i.start_server(port, timeout=.1)
+ for cl in clients:
+ cl.join()