def __init__(self, state, clock, log_dir, stopped, partitions, this_partition, build_duration, circuit_timeout, circuit_generator, log_chunk_size, max_concurrency): """ state: the txtorcon state object clock: this argument is normally the twisted global reactor object but unit tests might set this to a clock object which can time travel for faster testing. log_dir: the directory to write log files stopped: callable to call when done partitions: the number of partitions to use for processing the set of circuits this_partition: which partition of circuit we will process build_duration: build a new circuit every specified duration circuit_timeout: circuit build timeout duration """ self.state = state self.clock = clock self.log_dir = log_dir self.stopped = stopped self.partitions = partitions self.this_partition = this_partition self.circuit_life_duration = circuit_timeout self.circuit_build_duration = build_duration self.circuits = circuit_generator self.log_chunk_size = log_chunk_size self.semaphore = defer.DeferredSemaphore(max_concurrency) self.lazy_tail = defer.succeed(None) self.tasks = {} self.call_id = None # XXX adjust me self.result_sink = ResultSink(log_dir, chunk_size=log_chunk_size)
def test_end_flush(self): self.tmpdir = mkdtemp() chunk_size = 10 self.result_sink = ResultSink(self.tmpdir, chunk_size=chunk_size) test_data = {'test_method': 'test_send_chunk_size'} deferreds = [] for _ in xrange(chunk_size + 3): deferreds += [self.result_sink.send(test_data)] def validate(_, dirname, fnames): # assert len(fnames) == 1 for fname in fnames: path = join(dirname, fname) with open(path, 'r') as testfile: results = json.load(testfile) for result in results: assert 'test_method' in result assert result['test_method'] == 'test_send_chunk_size' dl = defer.DeferredList(deferreds) dl.addCallback(lambda results: self.result_sink.end_flush()) dl.addCallback(lambda results: walk(self.tmpdir, validate, None)) return dl