Skip to content

Commit

Permalink
A minor amount of cleanup before a PR
Browse files Browse the repository at this point in the history
  • Loading branch information
timwoj committed Dec 12, 2022
1 parent 3331fec commit abd5f37
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions btest
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,8 @@ def runSubprocess(*args, **kwargs):
q.put([success, rc])

try:
# Create a queue used for returning data from a process and then run the
# process itself.
q = mp.Queue()
p = mp.Process(target=child, args=(q, ))
p.start()
Expand Down Expand Up @@ -406,12 +408,16 @@ class TestManager(mp_managers.SyncManager):
self.threadRun(0)
else:
try:
# Create a set of processes for running each of the tests. This isn't the actual
# zeek processes, but more a container object for a test as it runs through its
# internal process calls.
for i in range(self._options.threads):
t = mp.Process(name="#%d" % (i + 1),
target=lambda: self.threadRun(i, mgr_data))
t.start()
threads += [t]

# Loop over the set of processes and wait for each one to complete.
for t in threads:
t.join()

Expand Down Expand Up @@ -447,20 +453,29 @@ class TestManager(mp_managers.SyncManager):
count = self._succeeded.value + self._failed.value + self._skipped.value
return 100.0 * count / self._num_tests

# Worker method for each of the "threads" specified by the "-j" argument passed
# at run time. This basically segments the list of tests into chunks and runs
# until we're out of chunks.
def threadRun(self, thread_num, mgr_data):
# This should prevent the child processes from receiving SIGINT signals and
# let the KeyboardInterrupt handler in the manager's run() method handle
# those.
signal.signal(signal.SIGINT, signal.SIG_IGN)

all_tests = []

while True:
tests = self.nextTests(thread_num)
if tests is None:
# Pull the next test from the list that was built at startup. This may
# be more than one test if there were alternatives requested in the
# arguments passed to btest.
thread_tests = self.nextTests(thread_num)
if thread_tests is None:
# No more work for us.
return

all_tests += tests
all_tests += thread_tests

for t in tests:
for t in thread_tests:
t.run(self, mgr_data)
self.testReplayOutput(t)

Expand Down

0 comments on commit abd5f37

Please sign in to comment.