This repository has been archived by the owner on Oct 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 284
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
concent acceptance test: force accept after force download
- Loading branch information
Showing
8 changed files
with
147 additions
and
20 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,22 @@ | ||
import logging | ||
|
||
from ethereum import slogging | ||
|
||
|
||
# Monkey patch for ethereum.slogging. | ||
# SLogger aggressively mess up with python logger. | ||
# This patch is to settle down this. | ||
# It should be done before any SLogger is created. | ||
|
||
|
||
orig_getLogger = slogging.SManager.getLogger | ||
|
||
|
||
def monkey_patched_getLogger(*args, **kwargs): | ||
orig_class = logging.getLoggerClass() | ||
result = orig_getLogger(*args, **kwargs) | ||
logging.setLoggerClass(orig_class) | ||
return result | ||
|
||
|
||
slogging.SManager.getLogger = monkey_patched_getLogger |
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
60 changes: 60 additions & 0 deletions
60
scripts/concent_acceptance_tests/force_accept_after_force_download.py
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,60 @@ | ||
import datetime | ||
import logging | ||
import time | ||
|
||
from golem_messages import message | ||
|
||
from golem.network.concent.filetransfers import ConcentFileRequest | ||
|
||
from .force_download.test_filetransfers import TestBase as ForceDownloadTestBase | ||
from .force_accept.test_requestor_doesnt_send import TestBase \ | ||
as ForceAcceptTestBase | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class Test(ForceDownloadTestBase, ForceAcceptTestBase): | ||
def _test_upload_fail(self): | ||
wrong_hash = "sha1:adeab1829629b4e1a19dc197f2e85603ee0b5cb4" | ||
offset_seconds = 61 | ||
fgtr = self.get_fgtr( | ||
ttc_kwargs={ | ||
'compute_task_def__deadline': int(time.time()) + offset_seconds | ||
}, | ||
report_computed_task__size=self.size, | ||
report_computed_task__package_hash=wrong_hash, | ||
) | ||
self.requestor_send(fgtr) | ||
fgtru = self.provider_receive() | ||
self.assertIsInstance(fgtru, message.concents.ForceGetTaskResultUpload) | ||
|
||
ftt = fgtru.file_transfer_token | ||
file_request = ConcentFileRequest(self.filename, ftt) | ||
upload_response = self.provider_cfts.upload(file_request) | ||
self._log_concent_response(upload_response) | ||
|
||
self.assertEqual(upload_response.status_code, 400) | ||
timeout = ftt.token_expiration_deadline + offset_seconds | ||
logger.debug("timeout: %s", datetime.datetime.fromtimestamp(timeout)) | ||
fgtrf = None | ||
|
||
# Currently concent treats wrong hash as an upload that didn't took | ||
# place, so we have to wait for timeout. | ||
while not fgtrf and time.time() < timeout: | ||
fgtrf = self.requestor_receive() | ||
time.sleep(60) | ||
|
||
self.assertIsInstance(fgtrf, message.concents.ForceGetTaskResultFailed) | ||
self.assertEqual(fgtrf.subtask_id, fgtru.subtask_id) | ||
return fgtrf | ||
|
||
def test_requestor_responds_with_fgtrf(self): | ||
fgtrf = self._test_upload_fail() | ||
|
||
response_to_force = self.provider_send_force(ttc=fgtrf.task_to_compute) | ||
self.assertIsInstance(response_to_force, | ||
message.concents.ServiceRefused) | ||
self.assertEqual( | ||
response_to_force.reason, | ||
message.concents.ServiceRefused.REASON.DuplicateRequest | ||
) |
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
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,3 @@ | ||
[pytest] | ||
log_cli=true | ||
log_level=DEBUG |
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