示例#1
0
 def test__solicitation_wins_when_multiple_requests_queued(self):
     # Note: Always use a random port for testing. (port=0)
     clock = Clock()
     protocol = BeaconingSocketProtocol(
         clock,
         port=0,
         process_incoming=False,
         loopback=True,
         interface="::",
         debug=True,
     )
     # Don't try to send out any replies.
     self.patch(services, "create_beacon_payload")
     send_mcast_mock = self.patch(protocol, "send_multicast_beacons")
     self.patch(protocol, "send_beacon")
     yield protocol.queueMulticastBeaconing()
     yield protocol.queueMulticastBeaconing(solicitation=True)
     clock.advance(5)
     self.assertThat(send_mcast_mock, MockCalledOnceWith({},
                                                         "solicitation"))
示例#2
0
 def test__multicasts_at_most_once_per_five_seconds(self):
     # Note: Always use a random port for testing. (port=0)
     clock = Clock()
     protocol = BeaconingSocketProtocol(
         clock,
         port=0,
         process_incoming=False,
         loopback=True,
         interface="::",
         debug=True,
     )
     # Don't try to send out any replies.
     self.patch(services, "create_beacon_payload")
     monotonic_mock = self.patch(services.time, "monotonic")
     send_mcast_mock = self.patch(protocol, "send_multicast_beacons")
     self.patch(protocol, "send_beacon")
     monotonic_mock.side_effect = [
         # Initial queue
         6,
         # Initial dequeue
         6,
         # Second queue (hasn't yet been 5 seconds)
         10,
         # Third queue
         11,
         # Second dequeue
         11,
     ]
     yield protocol.queueMulticastBeaconing()
     clock.advance(0)
     self.assertThat(send_mcast_mock, MockCalledOnceWith({},
                                                         "advertisement"))
     send_mcast_mock.reset_mock()
     yield protocol.queueMulticastBeaconing()
     yield protocol.queueMulticastBeaconing(solicitation=True)
     clock.advance(4.9)
     self.assertThat(send_mcast_mock, MockNotCalled())
     clock.advance(0.1)
     self.assertThat(send_mcast_mock, MockCalledOnceWith({},
                                                         "solicitation"))