Replace distributor deferred list, with a simple for loop until I understand why the former breaks and the latter doesn't
This commit is contained in:
parent
dea5d4b03b
commit
dbe77ec79a
|
@ -115,10 +115,10 @@ class Signal(object):
|
||||||
failure.value,
|
failure.value,
|
||||||
failure.getTracebackObject()))
|
failure.getTracebackObject()))
|
||||||
if not self.suppress_failures:
|
if not self.suppress_failures:
|
||||||
raise failure
|
failure.raiseException()
|
||||||
deferreds.append(d.addErrback(eb))
|
deferreds.append(d.addErrback(eb))
|
||||||
|
results = []
|
||||||
result = yield defer.DeferredList(
|
for deferred in deferreds:
|
||||||
deferreds, fireOnOneErrback=not self.suppress_failures
|
result = yield deferred
|
||||||
)
|
results.append(results)
|
||||||
defer.returnValue(result)
|
defer.returnValue(results)
|
||||||
|
|
|
@ -13,12 +13,13 @@
|
||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
from tests import unittest
|
from . import unittest
|
||||||
from twisted.internet import defer
|
from twisted.internet import defer
|
||||||
|
|
||||||
from mock import Mock, patch
|
from mock import Mock, patch
|
||||||
|
|
||||||
from synapse.util.distributor import Distributor
|
from synapse.util.distributor import Distributor
|
||||||
|
from synapse.util.async import run_on_reactor
|
||||||
|
|
||||||
|
|
||||||
class DistributorTestCase(unittest.TestCase):
|
class DistributorTestCase(unittest.TestCase):
|
||||||
|
@ -26,6 +27,7 @@ class DistributorTestCase(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.dist = Distributor()
|
self.dist = Distributor()
|
||||||
|
|
||||||
|
@defer.inlineCallbacks
|
||||||
def test_signal_dispatch(self):
|
def test_signal_dispatch(self):
|
||||||
self.dist.declare("alert")
|
self.dist.declare("alert")
|
||||||
|
|
||||||
|
@ -33,10 +35,11 @@ class DistributorTestCase(unittest.TestCase):
|
||||||
self.dist.observe("alert", observer)
|
self.dist.observe("alert", observer)
|
||||||
|
|
||||||
d = self.dist.fire("alert", 1, 2, 3)
|
d = self.dist.fire("alert", 1, 2, 3)
|
||||||
|
yield d
|
||||||
self.assertTrue(d.called)
|
self.assertTrue(d.called)
|
||||||
observer.assert_called_with(1, 2, 3)
|
observer.assert_called_with(1, 2, 3)
|
||||||
|
|
||||||
|
@defer.inlineCallbacks
|
||||||
def test_signal_dispatch_deferred(self):
|
def test_signal_dispatch_deferred(self):
|
||||||
self.dist.declare("whine")
|
self.dist.declare("whine")
|
||||||
|
|
||||||
|
@ -50,8 +53,10 @@ class DistributorTestCase(unittest.TestCase):
|
||||||
self.assertFalse(d_outer.called)
|
self.assertFalse(d_outer.called)
|
||||||
|
|
||||||
d_inner.callback(None)
|
d_inner.callback(None)
|
||||||
|
yield d_outer
|
||||||
self.assertTrue(d_outer.called)
|
self.assertTrue(d_outer.called)
|
||||||
|
|
||||||
|
@defer.inlineCallbacks
|
||||||
def test_signal_catch(self):
|
def test_signal_catch(self):
|
||||||
self.dist.declare("alarm")
|
self.dist.declare("alarm")
|
||||||
|
|
||||||
|
@ -65,6 +70,7 @@ class DistributorTestCase(unittest.TestCase):
|
||||||
spec=["warning"]
|
spec=["warning"]
|
||||||
) as mock_logger:
|
) as mock_logger:
|
||||||
d = self.dist.fire("alarm", "Go")
|
d = self.dist.fire("alarm", "Go")
|
||||||
|
yield d
|
||||||
self.assertTrue(d.called)
|
self.assertTrue(d.called)
|
||||||
|
|
||||||
observers[0].assert_called_once("Go")
|
observers[0].assert_called_once("Go")
|
||||||
|
@ -81,23 +87,28 @@ class DistributorTestCase(unittest.TestCase):
|
||||||
|
|
||||||
self.dist.declare("whail")
|
self.dist.declare("whail")
|
||||||
|
|
||||||
observer = Mock()
|
class MyException(Exception):
|
||||||
observer.return_value = defer.fail(
|
pass
|
||||||
Exception("Oopsie")
|
|
||||||
)
|
@defer.inlineCallbacks
|
||||||
|
def observer():
|
||||||
|
yield run_on_reactor()
|
||||||
|
raise MyException("Oopsie")
|
||||||
|
|
||||||
self.dist.observe("whail", observer)
|
self.dist.observe("whail", observer)
|
||||||
|
|
||||||
d = self.dist.fire("whail")
|
d = self.dist.fire("whail")
|
||||||
|
|
||||||
yield self.assertFailure(d, Exception)
|
yield self.assertFailure(d, MyException)
|
||||||
|
self.dist.suppress_failures = True
|
||||||
|
|
||||||
|
@defer.inlineCallbacks
|
||||||
def test_signal_prereg(self):
|
def test_signal_prereg(self):
|
||||||
observer = Mock()
|
observer = Mock()
|
||||||
self.dist.observe("flare", observer)
|
self.dist.observe("flare", observer)
|
||||||
|
|
||||||
self.dist.declare("flare")
|
self.dist.declare("flare")
|
||||||
self.dist.fire("flare", 4, 5)
|
yield self.dist.fire("flare", 4, 5)
|
||||||
|
|
||||||
observer.assert_called_with(4, 5)
|
observer.assert_called_with(4, 5)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue