tests: switch to defer.gatherResults

This commit is contained in:
Brian Warner 2015-09-28 16:44:00 -07:00
parent ea51617233
commit 5ae1c2d020
2 changed files with 14 additions and 32 deletions

View File

@ -1,6 +1,6 @@
import json import json
from twisted.trial import unittest from twisted.trial import unittest
from twisted.internet import defer from twisted.internet.defer import gatherResults
from twisted.internet.threads import deferToThread from twisted.internet.threads import deferToThread
from ..blocking.transcribe import Wormhole as BlockingWormhole, UsageError from ..blocking.transcribe import Wormhole as BlockingWormhole, UsageError
from .common import ServerBase from .common import ServerBase
@ -18,13 +18,10 @@ class Blocking(ServerBase, unittest.TestCase):
w2.set_code(code) w2.set_code(code)
d1 = deferToThread(w1.get_data, b"data1") d1 = deferToThread(w1.get_data, b"data1")
d2 = deferToThread(w2.get_data, b"data2") d2 = deferToThread(w2.get_data, b"data2")
return defer.DeferredList([d1,d2], fireOnOneErrback=False) return gatherResults([d1,d2], True)
d.addCallback(_got_code) d.addCallback(_got_code)
def _done(dl): def _done(dl):
((success1, dataX), (success2, dataY)) = dl (dataX, dataY) = dl
r1,r2 = dl
self.assertTrue(success1, dataX)
self.assertTrue(success2, dataY)
self.assertEqual(dataX, b"data2") self.assertEqual(dataX, b"data2")
self.assertEqual(dataY, b"data1") self.assertEqual(dataY, b"data1")
d.addCallback(_done) d.addCallback(_done)
@ -38,12 +35,9 @@ class Blocking(ServerBase, unittest.TestCase):
w2.set_code("123-purple-elephant") w2.set_code("123-purple-elephant")
d1 = deferToThread(w1.get_data, b"data1") d1 = deferToThread(w1.get_data, b"data1")
d2 = deferToThread(w2.get_data, b"data2") d2 = deferToThread(w2.get_data, b"data2")
d = defer.DeferredList([d1,d2], fireOnOneErrback=False) d = gatherResults([d1,d2], True)
def _done(dl): def _done(dl):
((success1, dataX), (success2, dataY)) = dl (dataX, dataY) = dl
r1,r2 = dl
self.assertTrue(success1, dataX)
self.assertTrue(success2, dataY)
self.assertEqual(dataX, b"data2") self.assertEqual(dataX, b"data2")
self.assertEqual(dataY, b"data1") self.assertEqual(dataY, b"data1")
d.addCallback(_done) d.addCallback(_done)
@ -81,13 +75,10 @@ class Blocking(ServerBase, unittest.TestCase):
new_w1 = BlockingWormhole.from_serialized(s) new_w1 = BlockingWormhole.from_serialized(s)
d1 = deferToThread(new_w1.get_data, b"data1") d1 = deferToThread(new_w1.get_data, b"data1")
d2 = deferToThread(w2.get_data, b"data2") d2 = deferToThread(w2.get_data, b"data2")
return defer.DeferredList([d1,d2], fireOnOneErrback=False) return gatherResults([d1,d2], True)
d.addCallback(_got_code) d.addCallback(_got_code)
def _done(dl): def _done(dl):
((success1, dataX), (success2, dataY)) = dl (dataX, dataY) = dl
r1,r2 = dl
self.assertTrue(success1, dataX)
self.assertTrue(success2, dataY)
self.assertEqual(dataX, b"data2") self.assertEqual(dataX, b"data2")
self.assertEqual(dataY, b"data1") self.assertEqual(dataY, b"data1")
self.assertRaises(UsageError, w2.serialize) # too late self.assertRaises(UsageError, w2.serialize) # too late

View File

@ -1,6 +1,6 @@
import sys, json import sys, json
from twisted.trial import unittest from twisted.trial import unittest
from twisted.internet import defer from twisted.internet.defer import gatherResults
from ..twisted.transcribe import Wormhole, UsageError from ..twisted.transcribe import Wormhole, UsageError
from .common import ServerBase from .common import ServerBase
@ -14,13 +14,10 @@ class Basic(ServerBase, unittest.TestCase):
w2.set_code(code) w2.set_code(code)
d1 = w1.get_data(b"data1") d1 = w1.get_data(b"data1")
d2 = w2.get_data(b"data2") d2 = w2.get_data(b"data2")
return defer.DeferredList([d1,d2], fireOnOneErrback=False) return gatherResults([d1,d2], True)
d.addCallback(_got_code) d.addCallback(_got_code)
def _done(dl): def _done(dl):
((success1, dataX), (success2, dataY)) = dl (dataX, dataY) = dl
r1,r2 = dl
self.assertTrue(success1, dataX)
self.assertTrue(success2, dataY)
self.assertEqual(dataX, b"data2") self.assertEqual(dataX, b"data2")
self.assertEqual(dataY, b"data1") self.assertEqual(dataY, b"data1")
d.addCallback(_done) d.addCallback(_done)
@ -34,12 +31,9 @@ class Basic(ServerBase, unittest.TestCase):
w2.set_code("123-purple-elephant") w2.set_code("123-purple-elephant")
d1 = w1.get_data(b"data1") d1 = w1.get_data(b"data1")
d2 = w2.get_data(b"data2") d2 = w2.get_data(b"data2")
d = defer.DeferredList([d1,d2], fireOnOneErrback=False) d = gatherResults([d1,d2], True)
def _done(dl): def _done(dl):
((success1, dataX), (success2, dataY)) = dl (dataX, dataY) = dl
r1,r2 = dl
self.assertTrue(success1, dataX)
self.assertTrue(success2, dataY)
self.assertEqual(dataX, b"data2") self.assertEqual(dataX, b"data2")
self.assertEqual(dataY, b"data1") self.assertEqual(dataY, b"data1")
d.addCallback(_done) d.addCallback(_done)
@ -75,13 +69,10 @@ class Basic(ServerBase, unittest.TestCase):
new_w1 = Wormhole.from_serialized(s) new_w1 = Wormhole.from_serialized(s)
d1 = new_w1.get_data(b"data1") d1 = new_w1.get_data(b"data1")
d2 = w2.get_data(b"data2") d2 = w2.get_data(b"data2")
return defer.DeferredList([d1,d2], fireOnOneErrback=False) return gatherResults([d1,d2], True)
d.addCallback(_got_code) d.addCallback(_got_code)
def _done(dl): def _done(dl):
((success1, dataX), (success2, dataY)) = dl (dataX, dataY) = dl
r1,r2 = dl
self.assertTrue(success1, dataX)
self.assertTrue(success2, dataY)
self.assertEqual(dataX, b"data2") self.assertEqual(dataX, b"data2")
self.assertEqual(dataY, b"data1") self.assertEqual(dataY, b"data1")
self.assertRaises(UsageError, w2.serialize) # too late self.assertRaises(UsageError, w2.serialize) # too late