Skip to content
This repository has been archived by the owner on Sep 12, 2022. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into pulse-3.1.4-prep
Browse files Browse the repository at this point in the history
  • Loading branch information
rdempsey committed Apr 11, 2017
2 parents 8710d4e + 02b092d commit 022859c
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 6 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,7 @@ build_full_environment.sh
docker-compose.build.yml

# Local environment things
.condaauto
.condaauto

# VS Code
/.vscode
32 changes: 32 additions & 0 deletions tests/test_traptor_offline.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,38 @@ def test_ensure_internal_rule_counters_are_correctly_made_for_rules(self, redis_
if traptor.traptor_type == 'locations':
assert len(traptor.rule_counters) == 0

def test_ensure_internal_rule_counters_are_properly_deleted(self, redis_rules, traptor):
"""Ensure _delete_rule_counters are properly deleted."""
traptor._setup()
traptor.redis_conn = redis_rules

traptor.logger.info = MagicMock()
traptor.logger.error = MagicMock()

traptor.redis_rules = [rule for rule in traptor._get_redis_rules()]
traptor.twitter_rules = traptor._make_twitter_rules(traptor.redis_rules)

if traptor.traptor_type != 'locations':
traptor._make_rule_counters()
assert len(traptor.rule_counters) == 1

if traptor.traptor_type == 'track':
assert traptor.rule_counters['12347'] is not None

traptor._delete_rule_counters()
assert traptor.logger.error.call_count == 0
assert traptor.logger.info.call_count == 3

if traptor.traptor_type == 'follow':
assert traptor.rule_counters['12345'] is not None

traptor._delete_rule_counters()
assert traptor.logger.error.call_count == 0
assert traptor.logger.info.call_count == 3

if traptor.traptor_type == 'locations':
assert len(traptor.rule_counters) == 0

def test_ensure_limit_message_counter_is_correctly_created(self, redis_rules, traptor):
"""Ensure _make_limit_message_counter makes the limit counter"""
traptor._setup()
Expand Down
15 changes: 10 additions & 5 deletions tests/traptor_integration_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
HOST_FOR_TESTING = os.getenv('REDIS_HOST', 'localhost')
TRAPTOR_TYPE = os.getenv('TRAPTOR_TYPE', 'track')
TRAPTOR_ID = int(os.getenv('TRAPTOR_ID', 0))
RULE_ID = 12348

# Create a connection to Redis

Expand All @@ -51,14 +52,18 @@
# Collect on tweets with the keyword `python`
# Change the rule value if you want to collect on a different keyword or hashtag. Go nuts!
test_track_rule = {
"tag": "Traptor.Test",
"type": "track",
"value": "python",
"description": "Test track rule for python"
"tag": "Traptor.Test",
"value": "python",
"status": "active",
"description": "Test track rule for python",
"appid": "test-appid",
"date_added": "2017-04-02 16:58:34",
"rule_type": "track",
"rule_id": RULE_ID
}

try:
redis_key = "traptor-{}:{}:{}".format(TRAPTOR_TYPE, TRAPTOR_ID, 123)
redis_key = "traptor-{}:{}:{}".format(TRAPTOR_TYPE, TRAPTOR_ID, RULE_ID)
redis_connection.hmset(redis_key, test_track_rule)

print("Rule added")
Expand Down
16 changes: 16 additions & 0 deletions traptor/traptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,21 @@ def _increment_rule_counter(self, tweet):
dd_monitoring.increment('redis_error',
tags=['error_type:connection_error'])

def _delete_rule_counters(self):
"""
Delete the existing rule counters.
"""
if len(self.rule_counters) > 0:
for counter in self.rule_counters:
try:
self.rule_counters[counter].delete_key()
except:
self.logger.error("Caught exception while deleting a rule counter", extra={
'error_type': 'RedisConnectionError',
'ex': traceback.format_exc()
})
self.logger.info("Rule counters deleted successfully.")

def _make_limit_message_counter(self):
"""
Make a limit message counter to track the values of incoming limit messages.
Expand Down Expand Up @@ -1032,6 +1047,7 @@ def run(self):

# Do all the things
while True:
self._delete_rule_counters()
self._wait_for_rules()

# Concatenate all of the rule['value'] fields
Expand Down

0 comments on commit 022859c

Please sign in to comment.