Skip to content

Commit

Permalink
Merge pull request #67 from spulec/cleanup-tests
Browse files Browse the repository at this point in the history
Cleanup tests
  • Loading branch information
spulec authored Nov 7, 2019
2 parents 4578578 + a939c55 commit 6fe8396
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 31 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ language: python
python:
- "2.7"
- "3.6"
- "3.7"
- "3.8"

sudo: false

Expand Down
2 changes: 1 addition & 1 deletion development.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
coverage==4.4.1
mock==1.0.1
moto==1.3.8
moto==1.3.13
nose==1.3.0
pre-commit==0.7.6
sure==1.2.2
Expand Down
12 changes: 4 additions & 8 deletions pyqs/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ def __init__(self, queue_prefixes, worker_concurrency, interval, batchsize,
self.batchsize = 1
self.interval = interval
self.prefetch_multiplier = prefetch_multiplier
self.load_queue_prefixes(queue_prefixes)
self.queue_prefixes = queue_prefixes
self.queue_urls = self.get_queue_urls_from_queue_prefixes(
self.queue_prefixes)
self.setup_internal_queue(worker_concurrency)
Expand Down Expand Up @@ -287,18 +287,14 @@ def _initialize_worker_children(self, number):
)
)

def load_queue_prefixes(self, queue_prefixes):
self.queue_prefixes = queue_prefixes

logger.info("Loading Queues:")
for queue_prefix in queue_prefixes:
logger.info("[Queue]\t{}".format(queue_prefix))

def get_queue_urls_from_queue_prefixes(self, queue_prefixes):
conn = get_conn(**self.connection_args)
queue_urls = conn.list_queues().get('QueueUrls', [])
matching_urls = []

logger.info("Loading Queues:")
for prefix in queue_prefixes:
logger.info("[Queue]\t{}".format(prefix))
matching_urls.extend([
queue_url for queue_url in queue_urls if
fnmatch.fnmatch(queue_url.rsplit("/", 1)[1], prefix)
Expand Down
14 changes: 1 addition & 13 deletions tests/test_manager_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import boto3
from mock import patch, Mock, MagicMock
from moto import mock_sqs, mock_sqs_deprecated
from moto import mock_sqs

from pyqs.main import main, _main
from pyqs.worker import ManagerWorker
Expand All @@ -16,7 +16,6 @@


@mock_sqs
@mock_sqs_deprecated
def test_manager_worker_create_proper_children_workers():
"""
Test managing process creates multiple child workers
Expand All @@ -34,7 +33,6 @@ def test_manager_worker_create_proper_children_workers():


@mock_sqs
@mock_sqs_deprecated
def test_manager_worker_with_queue_prefix():
"""
Test managing process can find queues by prefix
Expand All @@ -60,7 +58,6 @@ def test_manager_worker_with_queue_prefix():


@mock_sqs
@mock_sqs_deprecated
def test_manager_start_and_stop():
"""
Test managing process can start and stop child processes
Expand Down Expand Up @@ -91,7 +88,6 @@ def test_manager_start_and_stop():

@patch("pyqs.main.ManagerWorker")
@mock_sqs
@mock_sqs_deprecated
def test_main_method(ManagerWorker):
"""
Test creation of manager process from _main method
Expand All @@ -108,7 +104,6 @@ def test_main_method(ManagerWorker):
@patch("pyqs.main._main")
@patch("pyqs.main.ArgumentParser")
@mock_sqs
@mock_sqs_deprecated
def test_real_main_method(ArgumentParser, _main):
"""
Test parsing of arguments from main method
Expand All @@ -128,7 +123,6 @@ def test_real_main_method(ArgumentParser, _main):


@mock_sqs
@mock_sqs_deprecated
def test_master_spawns_worker_processes():
"""
Test managing process creates child workers
Expand All @@ -155,7 +149,6 @@ def test_master_spawns_worker_processes():

@patch("pyqs.worker.LONG_POLLING_INTERVAL", 1)
@mock_sqs
@mock_sqs_deprecated
def test_master_replaces_reader_processes():
"""
Test managing process replaces reader children
Expand Down Expand Up @@ -188,7 +181,6 @@ def test_master_replaces_reader_processes():


@mock_sqs
@mock_sqs_deprecated
def test_master_counts_processes():
"""
Test managing process counts child processes
Expand Down Expand Up @@ -223,7 +215,6 @@ def test_master_counts_processes():


@mock_sqs
@mock_sqs_deprecated
def test_master_replaces_worker_processes():
"""
Test managing process replaces worker processes
Expand Down Expand Up @@ -256,7 +247,6 @@ def test_master_replaces_worker_processes():

@mock_sqs
@patch("pyqs.worker.sys")
@mock_sqs_deprecated
def test_master_handles_signals(sys):
"""
Test managing process handles OS signals
Expand Down Expand Up @@ -291,7 +281,6 @@ def process_counts():

@patch("pyqs.worker.LONG_POLLING_INTERVAL", 3)
@mock_sqs
@mock_sqs_deprecated
def test_master_shuts_down_busy_read_workers():
"""
Test managing process properly cleans up busy Reader Workers
Expand Down Expand Up @@ -371,7 +360,6 @@ def sleep_and_kill(pid):


@mock_sqs
@mock_sqs_deprecated
def test_master_shuts_down_busy_process_workers():
"""
Test managing process properly cleans up busy Process Workers
Expand Down
8 changes: 1 addition & 7 deletions tests/test_tasks.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import json

import boto3
from moto import mock_sqs, mock_sqs_deprecated
from moto import mock_sqs

from .tasks import (
index_incrementer, send_email, delayed_task, custom_path_task,
)


@mock_sqs()
@mock_sqs_deprecated()
def test_basic_delay():
"""
Test delaying task to default queue
Expand Down Expand Up @@ -41,7 +40,6 @@ def test_basic_delay():


@mock_sqs()
@mock_sqs_deprecated()
def test_specified_queue():
"""
Test delaying task to specific queue
Expand All @@ -61,7 +59,6 @@ def test_specified_queue():


@mock_sqs()
@mock_sqs_deprecated()
def test_message_delay():
"""
Test delaying task with delay_seconds
Expand All @@ -81,7 +78,6 @@ def test_message_delay():


@mock_sqs()
@mock_sqs_deprecated()
def test_message_add_delay():
"""
Test configuring the delay time of a task
Expand All @@ -101,7 +97,6 @@ def test_message_add_delay():


@mock_sqs()
@mock_sqs_deprecated()
def test_message_no_delay():
"""
Test removing the delay time of a task
Expand All @@ -121,7 +116,6 @@ def test_message_no_delay():


@mock_sqs()
@mock_sqs_deprecated()
def test_custom_function_path():
"""
Test delaying task with custom function path
Expand Down
3 changes: 1 addition & 2 deletions tests/test_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,7 @@ def test_worker_processes_tasks_and_logs_warning_correctly():
logger.handlers[0].messages['error'][0].lower().should.contain(
msg1.lower())
msg2 = (
'"Need to be given basestring, was given '
'{}".format(message))\nValueError: Need to be given basestring, '
'ValueError: Need to be given basestring, '
'was given 23'
) # noqa
logger.handlers[0].messages['error'][0].lower().should.contain(
Expand Down

0 comments on commit 6fe8396

Please sign in to comment.