mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-01-19 03:06:33 +00:00
use foolscap.reconnector.Reconnector where one is required
Unfortunately we need to touch a private attribute directly to shove our expected info into it. This isn't so bad though. Foolscap isn't moving much and we're not touching anything complex, just setting a simple model attribute.
This commit is contained in:
parent
e2c6cc49d5
commit
6b7ea29d88
@ -6,11 +6,17 @@ import mock
|
||||
|
||||
from twisted.trial import unittest
|
||||
|
||||
from foolscap.reconnector import ReconnectionInfo
|
||||
from foolscap.reconnector import ReconnectionInfo, Reconnector
|
||||
from foolscap.info import ConnectionInfo
|
||||
|
||||
from ..util import connection_status
|
||||
|
||||
def reconnector(info: ReconnectionInfo) -> Reconnector:
|
||||
rc = Reconnector(None, None, (), {})
|
||||
rc._reconnectionInfo = info
|
||||
return rc
|
||||
|
||||
|
||||
class Status(unittest.TestCase):
|
||||
def test_hint_statuses(self):
|
||||
ncs = connection_status._hint_statuses(["h2","h1"],
|
||||
@ -29,8 +35,7 @@ class Status(unittest.TestCase):
|
||||
ri = ReconnectionInfo()
|
||||
ri.state = "connected"
|
||||
ri.connectionInfo = ci
|
||||
rc = mock.Mock
|
||||
rc.getReconnectionInfo = mock.Mock(return_value=ri)
|
||||
rc = reconnector(ri)
|
||||
cs = connection_status.from_foolscap_reconnector(rc, 123)
|
||||
self.assertEqual(cs.connected, True)
|
||||
self.assertEqual(cs.summary, "Connected to h1 via hand1")
|
||||
@ -47,8 +52,7 @@ class Status(unittest.TestCase):
|
||||
ri = ReconnectionInfo()
|
||||
ri.state = "connected"
|
||||
ri.connectionInfo = ci
|
||||
rc = mock.Mock
|
||||
rc.getReconnectionInfo = mock.Mock(return_value=ri)
|
||||
rc = reconnector(ri)
|
||||
cs = connection_status.from_foolscap_reconnector(rc, 123)
|
||||
self.assertEqual(cs.connected, True)
|
||||
self.assertEqual(cs.summary, "Connected to h1 via hand1")
|
||||
@ -66,8 +70,7 @@ class Status(unittest.TestCase):
|
||||
ri = ReconnectionInfo()
|
||||
ri.state = "connected"
|
||||
ri.connectionInfo = ci
|
||||
rc = mock.Mock
|
||||
rc.getReconnectionInfo = mock.Mock(return_value=ri)
|
||||
rc = reconnector(ri)
|
||||
cs = connection_status.from_foolscap_reconnector(rc, 123)
|
||||
self.assertEqual(cs.connected, True)
|
||||
self.assertEqual(cs.summary, "Connected via listener (listener1)")
|
||||
@ -83,8 +86,7 @@ class Status(unittest.TestCase):
|
||||
ri = ReconnectionInfo()
|
||||
ri.state = "connecting"
|
||||
ri.connectionInfo = ci
|
||||
rc = mock.Mock
|
||||
rc.getReconnectionInfo = mock.Mock(return_value=ri)
|
||||
rc = reconnector(ri)
|
||||
cs = connection_status.from_foolscap_reconnector(rc, 123)
|
||||
self.assertEqual(cs.connected, False)
|
||||
self.assertEqual(cs.summary, "Trying to connect")
|
||||
@ -102,8 +104,7 @@ class Status(unittest.TestCase):
|
||||
ri.lastAttempt = 10
|
||||
ri.nextAttempt = 20
|
||||
ri.connectionInfo = ci
|
||||
rc = mock.Mock
|
||||
rc.getReconnectionInfo = mock.Mock(return_value=ri)
|
||||
rc = reconnector(ri)
|
||||
with mock.patch("time.time", return_value=12):
|
||||
cs = connection_status.from_foolscap_reconnector(rc, 5)
|
||||
self.assertEqual(cs.connected, False)
|
||||
|
Loading…
Reference in New Issue
Block a user