fc437f4007
The new process pool allows adding jobs after testing has been started. It will also allow to restructure building the job queue (in a follow up CL), so that testing can start instantly while the queue is being built. Also attempts to clean up the keyboard-interrupt logic. Idea: Only catch keyboard interrupt once per process at the outermost level. Use proper "finally" clauses to clean up everywhere where a keyboard interrupt might occur. Never turn named exceptions into none-exceptions using anonymous "raise". TEST=python -m unittest pool_unittest R=jkummerow@chromium.org Review URL: https://codereview.chromium.org/275093002 git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@21310 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
42 lines
1.2 KiB
Python
42 lines
1.2 KiB
Python
#!/usr/bin/env python
|
|
# Copyright 2014 the V8 project authors. All rights reserved.
|
|
# Use of this source code is governed by a BSD-style license that can be
|
|
# found in the LICENSE file.
|
|
|
|
import unittest
|
|
|
|
from pool import Pool
|
|
|
|
def Run(x):
|
|
if x == 10:
|
|
raise Exception("Expected exception triggered by test.")
|
|
return x
|
|
|
|
class PoolTest(unittest.TestCase):
|
|
def testNormal(self):
|
|
results = set()
|
|
pool = Pool(3)
|
|
for result in pool.imap_unordered(Run, [[x] for x in range(0, 10)]):
|
|
results.add(result)
|
|
self.assertEquals(set(range(0, 10)), results)
|
|
|
|
def testException(self):
|
|
results = set()
|
|
pool = Pool(3)
|
|
for result in pool.imap_unordered(Run, [[x] for x in range(0, 12)]):
|
|
# Item 10 will not appear in results due to an internal exception.
|
|
results.add(result)
|
|
expect = set(range(0, 12))
|
|
expect.remove(10)
|
|
self.assertEquals(expect, results)
|
|
|
|
def testAdd(self):
|
|
results = set()
|
|
pool = Pool(3)
|
|
for result in pool.imap_unordered(Run, [[x] for x in range(0, 10)]):
|
|
results.add(result)
|
|
if result < 30:
|
|
pool.add([result + 20])
|
|
self.assertEquals(set(range(0, 10) + range(20, 30) + range(40, 50)),
|
|
results)
|