コード例 #1
0
ファイル: test_tasks.py プロジェクト: SergioLaime/txscada
 def testRequestAndAccept(self):
     task = MockTask(lambda x: 10*x, (2,), {}, 100, None)
     worker = MockWorker()
     worker.hired = False
     self.af.request(worker, None)
     d = defer.DeferredList([self.af.new(task), task.d])
     d.addCallback(lambda _: self.failUnlessEqual(worker.ran, [task]))
     return d
コード例 #2
0
ファイル: test_tasks.py プロジェクト: SergioLaime/txscada
    def testRequestBasic(self):
        OriginalAssignment = tasks.Assignment
        
        class ModifiedAssignment(tasks.Assignment):
            mutable = []
            def accept(self, worker):
                self.mutable.append(worker)
                self.d.callback(None)

        def finishUp(null, worker):
            self.failUnlessEqual(ModifiedAssignment.mutable, [worker])
            tasks.Assignment = OriginalAssignment

        tasks.Assignment = ModifiedAssignment
        task = MockTask(lambda x: 10*x, (2,), {}, 100, None)
        worker = MockWorker()
        worker.hired = False
        self.af.request(worker, None)
        for dList in worker.assignments.itervalues():
            self.failUnlessEqual(
                [isinstance(x, defer.Deferred) for x in dList], [True])
        d = self.af.new(task)
        d.addCallback(finishUp, worker)
        return d