Handle double-disconnect, should it happen by mistake.

This commit is contained in:
Itamar Turner-Trauring 2021-10-06 15:18:00 -04:00
parent 23fd11be43
commit bf176144c5

View File

@ -314,10 +314,15 @@ class FakeCanary(object):
def getPeer(self):
return "<fake>"
# For use by tests:
def disconnected(self):
for (f, args, kwargs) in list(self.disconnectors.values()):
f(*args, **kwargs)
"""Disconnect the canary, to be called by test code.
Can only happen once.
"""
if self.disconnectors is not None:
for (f, args, kwargs) in list(self.disconnectors.values()):
f(*args, **kwargs)
self.disconnectors = None
class ShouldFailMixin(object):