Commit 34285a1b authored by Luke Macken's avatar Luke Macken

Fix our multi-threaded unit tests

parent 13241381
......@@ -47,8 +47,8 @@ class TestCodeInjection(unittest.TestCase):
os.unlink(program)
def test_many_payloads_into_program_with_many_threads(self):
program = generate_program(threads=50)
num_payloads = 50
program = generate_program(threads=25)
num_payloads = 25
try:
for exe in interpreters():
p = run_program(program, exe=exe)
......
......@@ -30,21 +30,20 @@ def generate_program(threads=1):
import os, time, threading
running = True
pidfile = '/tmp/pyrasite_%d' % os.getpid()
open(pidfile, 'w').close()
def cpu_bound():
i = 2
y = 0
def fib(n):
return fib(n - 1) + fib(n - 2)
i = 0
while running:
y += fib(i)
i += 1
while os.path.exists(pidfile):
time.sleep(0.1)
""")
# CPU-bound threads
for t in range(threads):
script += "threading.Thread(target=cpu_bound).start()\n"
script += "open(pidfile, 'w').close()\n"
script += textwrap.dedent("""
while os.path.exists(pidfile):
time.sleep(0.1)
running = False
""")
tmp.write(script)
tmp.close()
return filename
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment