def send_sync(self, synced=False): state_str = '' if synced: state_str = 'Synced' msg = qrllegacy_pb2.LegacyMessage(func_name=qrllegacy_pb2.LegacyMessage.SYNC, syncData=qrllegacy_pb2.SYNCData(state=state_str)) self.send(msg)
def test_handle_sync(self): """ If a message comes in saying 'Synced': the peer is synced. """ sync_message = qrllegacy_pb2.LegacyMessage( func_name=qrllegacy_pb2.LegacyMessage.SYNC, syncData=qrllegacy_pb2.SYNCData(state='Synced')) channel = make_channel() self.peer_manager.handle_sync(channel, sync_message)
def test_handle_sync_unsynced(self): """ If the message says anything else: the peer is unsynced. """ sync_message = qrllegacy_pb2.LegacyMessage( func_name=qrllegacy_pb2.LegacyMessage.SYNC, syncData=qrllegacy_pb2.SYNCData(state='Unsynced')) channel = make_channel() self.peer_manager.handle_sync(channel, sync_message)
def test_handle_sync(self): """ If a message comes in saying 'Synced': the peer is synced. """ sync_message = qrllegacy_pb2.LegacyMessage( func_name=qrllegacy_pb2.LegacyMessage.SYNC, syncData=qrllegacy_pb2.SYNCData(state='Synced')) channel = make_channel() self.peer_manager.handle_sync(channel, sync_message) channel.factory.set_peer_synced.assert_called_once_with(channel, True)
def test_handle_sync_blank(self): """ If the message says '': the peer doesn't know, and isn't synced. We tell it that we are synced. """ sync_message = qrllegacy_pb2.LegacyMessage( func_name=qrllegacy_pb2.LegacyMessage.SYNC, syncData=qrllegacy_pb2.SYNCData(state='')) channel = make_channel() # But if we ourselves aren't synced, then we cannot say if anybody else is synced. channel.factory.synced = False self.peer_manager.handle_sync(channel, sync_message) channel.send_sync.assert_not_called() # If we are synced, then we can tell other nodes we are synced. channel.factory.synced = True self.peer_manager.handle_sync(channel, sync_message) channel.send_sync.assert_called_once_with(synced=True)