-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_all.py
60 lines (47 loc) · 1.44 KB
/
test_all.py
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
49
50
51
52
53
54
55
56
57
58
59
60
"""
This tests both the server and the client, by uppercasing the content of
different files.
"""
import os
import tempfile
import threading
import time
from jqueue import quickstart, server
# These are the names of the jobs, as well as their content
IN_FILES = {
'A': 'a lowercase test',
'B': 'miXeD-caSe',
'C': 'UPPER CASE'
}
OUT_FILES = {
'A.result': 'A LOWERCASE TEST',
'B.result': 'MIXED-CASE',
'C.result': 'UPPER-CASE'
}
svr = server.Server()
def server_thread_runner():
svr.run([fname.encode('ascii') for fname in IN_FILES])
def client_thread_runner():
def handler(data):
return data.upper()
quickstart.process_jobs('localhost', handler, ttl=5)
with tempfile.TemporaryDirectory() as tmpdir:
os.chdir(tmpdir)
for fname in IN_FILES:
with open(fname, 'w') as fstream:
fstream.write(IN_FILES[fname])
server_thread = threading.Thread(target=server_thread_runner, name='Server')
client_threads = [
threading.Thread(target=client_thread_runner, name='Client')
for _ in range(2)]
server_thread.start()
for thread in client_threads:
thread.start()
server_thread.join()
for thread in client_threads:
thread.join()
for fname in OUT_FILES:
with open(fname) as fstream:
content = fstream.read()
print('[{}]'.format(fname), repr(content), '==', repr(OUT_FILES[fname]))
input('Press Enter to continue')