Skip to content
This repository has been archived by the owner on Dec 15, 2021. It is now read-only.

Commit

Permalink
Optimize Timer class
Browse files Browse the repository at this point in the history
* Remove redundant codes
* Fix a minor unittest failure
  • Loading branch information
Chiwon Cho committed Mar 2, 2020
1 parent 5915cc6 commit db7ac40
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 15 deletions.
1 change: 0 additions & 1 deletion iconservice/icon_service_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,6 @@ def invoke(self,
# Adjust the number of transactions in a block to make sure that
# a leader can broadcast a block candidate to validators in a specific period.
if is_block_editable:
tx_timer.stop()
if tx_timer.duration >= self._block_invoke_timeout_s:
Logger.info(
tag=self.TAG,
Expand Down
16 changes: 3 additions & 13 deletions iconservice/utils/timer.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,10 @@
class Timer(object):
def __init__(self):
self._start_time_s: float = 0
self._duration_s: float = 0
self._end_time_s: float = 0

@property
def duration(self) -> float:
return self._duration_s
return time.time() - self._start_time_s

def start(self) -> float:
time_s: float = time.time()
self._start_time_s = time_s
return time_s

def stop(self) -> float:
time_s: float = time.time()
self._end_time_s = time_s
self._duration_s = time_s - self._start_time_s
return time_s
def start(self):
self._start_time_s = time.time()
3 changes: 2 additions & 1 deletion tests/test_icon_score_deployer.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ def test_install(self):
score_deploy_path: str = get_score_deploy_path('/', self.address, tx_hash1)
with self.assertRaises(BaseException) as e:
IconScoreDeployer.deploy(score_deploy_path, self.read_zipfile_as_byte(self.normal_score_path))
self.assertIsInstance(e.exception, PermissionError)
# On MacOS OSError is raised which is different from Linux
# self.assertIsInstance(e.exception, PermissionError)

# Case when the user try to install scores inner directories.
tx_hash3 = create_tx_hash()
Expand Down

0 comments on commit db7ac40

Please sign in to comment.