-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: Orchestrator failed with `assert result["result"] == HTTPOk.stat…
…us_code` Problem: The diagnostic VM returned HTTP 200 with {"result": False} when it could not connect to the internet. Since this is an OK return code, `raise_for_status` did not raise an error and an assertion error was raised. Solution: Test that the returned status code also corresponds to HTTP OK.
- Loading branch information
Showing
2 changed files
with
48 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from unittest.mock import AsyncMock, MagicMock, Mock | ||
|
||
import pytest | ||
from aleph_message.models import ItemHash | ||
|
||
from aleph.vm.orchestrator.status import check_internet | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_check_internet_no_server_header(): | ||
vm_id = ItemHash("cafecafecafecafecafecafecafecafecafecafecafecafecafecafecafecafe") | ||
|
||
mock_session = Mock() | ||
mock_session.get = MagicMock() | ||
mock_session.get.__aenter__.return_value.json = AsyncMock(return_value={"result": 200}) | ||
|
||
# A "Server" header is always expected in the result from the VM. | ||
# If it is not present, the diagnostic VM is not working correctly | ||
# and an error must be raised. | ||
with pytest.raises(ValueError): | ||
await check_internet(mock_session, vm_id) | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_check_internet_wrong_result_code(): | ||
vm_id = ItemHash("cafecafecafecafecafecafecafecafecafecafecafecafecafecafecafecafe") | ||
|
||
mock_session = Mock() | ||
mock_session.get = MagicMock() | ||
|
||
mock_session.get.return_value.__aenter__.return_value.json = AsyncMock( | ||
return_value={"result": 200, "headers": {"Server": "nginx"}} | ||
) | ||
assert await check_internet(mock_session, vm_id) is True | ||
|
||
mock_session.get.return_value.__aenter__.return_value.json = AsyncMock( | ||
return_value={"result": 400, "headers": {"Server": "nginx"}} | ||
) | ||
assert await check_internet(mock_session, vm_id) is False |