Skip to content

Commit

Permalink
Change get_event_loop with get_running_loop
Browse files Browse the repository at this point in the history
  • Loading branch information
drew2a committed May 2, 2022
1 parent 6800cde commit 288a87d
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ def test_send_scheduled_with_transfers_limit(eva: EVAProtocol):
assert len(eva.scheduled['peer3']) == 1


def test_send_write_request_finished_transfer(eva: EVAProtocol):
async def test_send_write_request_finished_transfer(eva: EVAProtocol):
transfer = OutgoingTransfer(container=eva.outgoing, peer=Mock(), info=b'123', data=b'456', nonce=42,
settings=EVASettings())
transfer.finished = True
Expand Down
2 changes: 1 addition & 1 deletion src/tribler/core/components/ipv8/eva/transfer/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def __init__(self, container: Dict[Peer, Type[Transfer]], peer: Peer, info: byte
self.on_complete = on_complete
self.on_error = on_error
self.settings = settings
self.future = asyncio.get_event_loop().create_future()
self.future = asyncio.get_running_loop().create_future()
self.logger = logging.getLogger(self.__class__.__name__)
self.updated = 0
self.attempt = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# pylint: disable=redefined-outer-name, protected-access

@pytest.fixture
def transfer() -> Transfer:
async def transfer() -> Transfer:
peer = Mock()
container = {}
transfer = Transfer(container=container, info=b'info', data_size=100, nonce=0, on_complete=AsyncMock(), peer=peer,
Expand All @@ -22,13 +22,13 @@ def transfer() -> Transfer:


@patch('time.time', Mock(return_value=42))
def test_update(transfer: Transfer):
async def test_update(transfer: Transfer):
transfer.update()

assert transfer.updated == 42


def test_finish_double_call(transfer: Transfer):
async def test_finish_double_call(transfer: Transfer):
assert not transfer.finished

# The first call of the finish method should process exception and result
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@


@pytest.fixture
def incoming_transfer() -> IncomingTransfer:
async def incoming_transfer() -> IncomingTransfer:
settings = EVASettings(block_size=10)
eva = EVAProtocol(Mock(), settings=settings)
peer = Mock()
Expand All @@ -25,7 +25,7 @@ def incoming_transfer() -> IncomingTransfer:
return transfer


def test_on_data_normal_packet(incoming_transfer: IncomingTransfer):
async def test_on_data_normal_packet(incoming_transfer: IncomingTransfer):
incoming_transfer.window = Mock(is_finished=Mock(return_value=False))
incoming_transfer.make_acknowledgement = Mock()
incoming_transfer.update = Mock()
Expand All @@ -39,7 +39,7 @@ def test_on_data_normal_packet(incoming_transfer: IncomingTransfer):
assert not incoming_transfer.make_acknowledgement.called


def test_on_data_window_is_finished(incoming_transfer: IncomingTransfer):
async def test_on_data_window_is_finished(incoming_transfer: IncomingTransfer):
incoming_transfer.window = Mock(is_finished=Mock(return_value=True))
incoming_transfer.make_acknowledgement = Mock()
incoming_transfer.update = Mock()
Expand All @@ -54,7 +54,7 @@ def test_on_data_window_is_finished(incoming_transfer: IncomingTransfer):
assert not incoming_transfer.finished


def test_on_data_window_is_last_and_finished(incoming_transfer: IncomingTransfer):
async def test_on_data_window_is_last_and_finished(incoming_transfer: IncomingTransfer):
incoming_transfer.window = Mock(is_finished=Mock(return_value=True))
incoming_transfer.make_acknowledgement = Mock()
incoming_transfer.update = Mock()
Expand All @@ -71,7 +71,7 @@ def test_on_data_window_is_last_and_finished(incoming_transfer: IncomingTransfer
assert incoming_transfer.finish.called


def test_on_data_final_packet(incoming_transfer: IncomingTransfer):
async def test_on_data_final_packet(incoming_transfer: IncomingTransfer):
incoming_transfer.window = TransferWindow(0, 10)
index = 3

Expand All @@ -81,7 +81,7 @@ def test_on_data_final_packet(incoming_transfer: IncomingTransfer):
assert len(incoming_transfer.window.blocks) == index + 1


def test_make_acknowledgement_no_window(incoming_transfer: IncomingTransfer):
async def test_make_acknowledgement_no_window(incoming_transfer: IncomingTransfer):
assert not incoming_transfer.window

acknowledgement = incoming_transfer.make_acknowledgement()
Expand All @@ -92,7 +92,7 @@ def test_make_acknowledgement_no_window(incoming_transfer: IncomingTransfer):
assert acknowledgement.window_size == incoming_transfer.settings.window_size


def test_make_acknowledgement_next_window(incoming_transfer: IncomingTransfer):
async def test_make_acknowledgement_next_window(incoming_transfer: IncomingTransfer):
incoming_transfer.window = TransferWindow(10, 7)
incoming_transfer.window.blocks = [b'd', b'a', b't', b'a', None, None, None]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# pylint: disable=redefined-outer-name, protected-access

@pytest.fixture
def outgoing_transfer() -> OutgoingTransfer:
async def outgoing_transfer() -> OutgoingTransfer:
settings = EVASettings(block_size=2)
eva = EVAProtocol(Mock(), settings=settings)
peer = Mock()
Expand All @@ -25,20 +25,20 @@ def outgoing_transfer() -> OutgoingTransfer:
return transfer


def test_size_exception():
async def test_size_exception():
settings = EVASettings(binary_size_limit=10)
limit = settings.binary_size_limit
with pytest.raises(SizeException):
OutgoingTransfer(container=Mock(), info=b'info', data=b'd' * (limit + 1), nonce=0, on_complete=AsyncMock(),
peer=Mock(), settings=settings)


def test_block_count(outgoing_transfer: OutgoingTransfer):
async def test_block_count(outgoing_transfer: OutgoingTransfer):
# data is b'binary_data' and block_size is `2`
assert outgoing_transfer.block_count == 6


def test_on_acknowledgement(outgoing_transfer: OutgoingTransfer):
async def test_on_acknowledgement(outgoing_transfer: OutgoingTransfer):
assert not outgoing_transfer.acknowledgement_received
assert not outgoing_transfer.updated

Expand All @@ -59,7 +59,7 @@ def test_on_acknowledgement(outgoing_transfer: OutgoingTransfer):
assert all(a.data == e.data and a.number == e.number for a, e in zip(actual, expected))


def test_on_final_acknowledgement(outgoing_transfer: OutgoingTransfer):
async def test_on_final_acknowledgement(outgoing_transfer: OutgoingTransfer):
outgoing_transfer.finish = Mock()
data_list = list(outgoing_transfer.on_acknowledgement(ack_number=10, window_size=16))
expected_result = TransferResult(peer=outgoing_transfer.peer, info=outgoing_transfer.info,
Expand All @@ -79,7 +79,7 @@ async def test_finish(outgoing_transfer: OutgoingTransfer):
assert not container


def test_get_block(outgoing_transfer: OutgoingTransfer):
async def test_get_block(outgoing_transfer: OutgoingTransfer):
assert outgoing_transfer._get_block(0) == b'bi'
assert outgoing_transfer._get_block(1) == b'na'
...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
# pylint: disable=redefined-outer-name

@pytest.fixture
def window() -> TransferWindow:
async def window() -> TransferWindow:
return TransferWindow(start=0, size=10)


def test_constructor(window: TransferWindow):
async def test_constructor(window: TransferWindow):
assert len(window.blocks) == 10
assert all(not block for block in window.blocks)


def test_add(window: TransferWindow):
async def test_add(window: TransferWindow):
window.add(0, b'first')
window.add(0, b'first')
window.add(9, b'last')
Expand All @@ -25,15 +25,15 @@ def test_add(window: TransferWindow):
assert not window.is_finished()


def test_finished(window: TransferWindow):
async def test_finished(window: TransferWindow):
for i in range(10):
window.add(i, b'block')

assert window.processed == 10
assert window.is_finished()


def test_consecutive_blocks(window: TransferWindow):
async def test_consecutive_blocks(window: TransferWindow):
window.add(0, b'first')
window.add(1, b'second')
window.add(3, b'fourth')
Expand Down

0 comments on commit 288a87d

Please sign in to comment.