-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Delay task logs #4724
Merged
Merged
Delay task logs #4724
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d383929
Support for log_delay for all tasks
3fc40e1
Added configuration for log_delay
a0938b7
Added tests for log_delay
3287687
Rename log_delay in log_interval
4e0348a
Added log_interval to docs
a6d4e1a
Sync Branch + Resolve Conflitcs
6d783f4
Restored submodule reference
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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,62 @@ | ||
import unittest | ||
from datetime import timedelta, datetime | ||
from time import sleep | ||
|
||
from mock import patch, MagicMock | ||
|
||
from pokemongo_bot.cell_workers import MoveToFort | ||
from tests import FakeBot | ||
|
||
|
||
class LogDelayTestCase(unittest.TestCase): | ||
|
||
config = { | ||
"enabled": 'true', | ||
"lure_attraction": 'true', | ||
"lure_max_distance": 2000, | ||
"walker": "StepWalker", | ||
"log_delay": 3 | ||
} | ||
|
||
def setUp(self): | ||
self.bot = FakeBot() | ||
self.bot.event_manager = MagicMock() | ||
self.worker = MoveToFort(self.bot, self.config) | ||
|
||
def test_read_correct_delay_config(self): | ||
self.worker.config['log_delay'] = 3 | ||
self.assertEqual(self.config.get('log_delay'), 3) | ||
|
||
def test_log_with_no_delay(self): | ||
self.worker.config['log_delay'] = 3 | ||
# All those call should not happen cause without any delay between each other | ||
self.worker.emit_event('moving_to_fort', formatted="just an example") | ||
self.worker.emit_event('moving_to_fort', formatted="just an example") | ||
|
||
# Let's try to subtract 2 of 3 sec and see if event_manager.emit() get no call at all | ||
self.worker.last_log_time -= 2 | ||
self.worker.emit_event('moving_to_fort', formatted="just an example") | ||
self.worker.emit_event('moving_to_fort', formatted="just an example") | ||
|
||
self.assertEqual(self.bot.event_manager.emit.call_count, 0) | ||
assert not self.bot.event_manager.emit.called | ||
|
||
def test_correct_delay_wait(self): | ||
|
||
self.worker.config['log_delay'] = 2 | ||
|
||
# to avoid use sleep() function here, we subtract expected log_delay to last_log_time | ||
self.worker.last_log_time -= self.worker.config['log_delay'] | ||
|
||
for number_of_checks in range(10): | ||
self.worker.emit_event('moving_to_fort', formatted="just an example") | ||
self.worker.last_log_time -= 2 | ||
|
||
self.assertEqual(self.bot.event_manager.emit.call_count, 10) | ||
|
||
# i think should be better assert in this way, but can't get it working | ||
# assert self.bot.event_manager.emit.assert_any_call('moving_to_fort', | ||
# sender=None, | ||
# level='info', | ||
# formatted="just an example",data={}) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm, log_delay the wording lead me misunderstood. I was thinking the log will delay to show, that's not what you mean in code.
Any better wording suggestion since I'm not English natively speaking guy :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
log_interval maybe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or terminal_update_delay