tests: clean up pairs-of-Deferreds patterns
This commit is contained in:
parent
8d3ed79ce6
commit
429c5cd962
|
@ -16,9 +16,8 @@ class Blocking(ServerBase, unittest.TestCase):
|
||||||
d = deferToThread(w1.get_code)
|
d = deferToThread(w1.get_code)
|
||||||
def _got_code(code):
|
def _got_code(code):
|
||||||
w2.set_code(code)
|
w2.set_code(code)
|
||||||
d1 = deferToThread(w1.get_data, b"data1")
|
return gatherResults([deferToThread(w1.get_data, b"data1"),
|
||||||
d2 = deferToThread(w2.get_data, b"data2")
|
deferToThread(w2.get_data, b"data2")], True)
|
||||||
return gatherResults([d1,d2], True)
|
|
||||||
d.addCallback(_got_code)
|
d.addCallback(_got_code)
|
||||||
def _done(dl):
|
def _done(dl):
|
||||||
(dataX, dataY) = dl
|
(dataX, dataY) = dl
|
||||||
|
@ -33,9 +32,8 @@ class Blocking(ServerBase, unittest.TestCase):
|
||||||
w2 = BlockingWormhole(appid, self.relayurl)
|
w2 = BlockingWormhole(appid, self.relayurl)
|
||||||
w1.set_code("123-purple-elephant")
|
w1.set_code("123-purple-elephant")
|
||||||
w2.set_code("123-purple-elephant")
|
w2.set_code("123-purple-elephant")
|
||||||
d1 = deferToThread(w1.get_data, b"data1")
|
d = gatherResults([deferToThread(w1.get_data, b"data1"),
|
||||||
d2 = deferToThread(w2.get_data, b"data2")
|
deferToThread(w2.get_data, b"data2")], True)
|
||||||
d = gatherResults([d1,d2], True)
|
|
||||||
def _done(dl):
|
def _done(dl):
|
||||||
(dataX, dataY) = dl
|
(dataX, dataY) = dl
|
||||||
self.assertEqual(dataX, b"data2")
|
self.assertEqual(dataX, b"data2")
|
||||||
|
@ -114,9 +112,8 @@ class Blocking(ServerBase, unittest.TestCase):
|
||||||
unpacked = json.loads(s) # this is supposed to be JSON
|
unpacked = json.loads(s) # this is supposed to be JSON
|
||||||
self.assertEqual(type(unpacked), dict)
|
self.assertEqual(type(unpacked), dict)
|
||||||
new_w1 = BlockingWormhole.from_serialized(s)
|
new_w1 = BlockingWormhole.from_serialized(s)
|
||||||
d1 = deferToThread(new_w1.get_data, b"data1")
|
return gatherResults([deferToThread(new_w1.get_data, b"data1"),
|
||||||
d2 = deferToThread(w2.get_data, b"data2")
|
deferToThread(w2.get_data, b"data2")], True)
|
||||||
return gatherResults([d1,d2], True)
|
|
||||||
d.addCallback(_got_code)
|
d.addCallback(_got_code)
|
||||||
def _done(dl):
|
def _done(dl):
|
||||||
(dataX, dataY) = dl
|
(dataX, dataY) = dl
|
||||||
|
|
|
@ -12,9 +12,8 @@ class Basic(ServerBase, unittest.TestCase):
|
||||||
d = w1.get_code()
|
d = w1.get_code()
|
||||||
def _got_code(code):
|
def _got_code(code):
|
||||||
w2.set_code(code)
|
w2.set_code(code)
|
||||||
d1 = w1.get_data(b"data1")
|
return gatherResults([w1.get_data(b"data1"),
|
||||||
d2 = w2.get_data(b"data2")
|
w2.get_data(b"data2")], True)
|
||||||
return gatherResults([d1,d2], True)
|
|
||||||
d.addCallback(_got_code)
|
d.addCallback(_got_code)
|
||||||
def _done(dl):
|
def _done(dl):
|
||||||
(dataX, dataY) = dl
|
(dataX, dataY) = dl
|
||||||
|
@ -29,9 +28,8 @@ class Basic(ServerBase, unittest.TestCase):
|
||||||
w2 = Wormhole(appid, self.relayurl)
|
w2 = Wormhole(appid, self.relayurl)
|
||||||
w1.set_code("123-purple-elephant")
|
w1.set_code("123-purple-elephant")
|
||||||
w2.set_code("123-purple-elephant")
|
w2.set_code("123-purple-elephant")
|
||||||
d1 = w1.get_data(b"data1")
|
d = gatherResults([w1.get_data(b"data1"),
|
||||||
d2 = w2.get_data(b"data2")
|
w2.get_data(b"data2")], True)
|
||||||
d = gatherResults([d1,d2], True)
|
|
||||||
def _done(dl):
|
def _done(dl):
|
||||||
(dataX, dataY) = dl
|
(dataX, dataY) = dl
|
||||||
self.assertEqual(dataX, b"data2")
|
self.assertEqual(dataX, b"data2")
|
||||||
|
@ -106,9 +104,8 @@ class Basic(ServerBase, unittest.TestCase):
|
||||||
unpacked = json.loads(s) # this is supposed to be JSON
|
unpacked = json.loads(s) # this is supposed to be JSON
|
||||||
self.assertEqual(type(unpacked), dict)
|
self.assertEqual(type(unpacked), dict)
|
||||||
new_w1 = Wormhole.from_serialized(s)
|
new_w1 = Wormhole.from_serialized(s)
|
||||||
d1 = new_w1.get_data(b"data1")
|
return gatherResults([new_w1.get_data(b"data1"),
|
||||||
d2 = w2.get_data(b"data2")
|
w2.get_data(b"data2")], True)
|
||||||
return gatherResults([d1,d2], True)
|
|
||||||
d.addCallback(_got_code)
|
d.addCallback(_got_code)
|
||||||
def _done(dl):
|
def _done(dl):
|
||||||
(dataX, dataY) = dl
|
(dataX, dataY) = dl
|
||||||
|
|
Loading…
Reference in New Issue
Block a user