From 11cfacd57ad844ba603a4edf109f6fabc0269e8a Mon Sep 17 00:00:00 2001 From: Matthew Jones Date: Tue, 18 Feb 2014 13:54:56 -0500 Subject: [PATCH] Update unit tests to manage zeromq based tasks --- awx/main/tests/base.py | 11 +++++++++++ awx/main/tests/commands.py | 2 ++ awx/main/tests/inventory.py | 5 +++++ awx/main/tests/jobs.py | 10 ++++++++++ awx/main/tests/projects.py | 5 +++++ awx/main/tests/tasks.py | 2 ++ 6 files changed, 35 insertions(+) diff --git a/awx/main/tests/base.py b/awx/main/tests/base.py index 23f851d6e9..e4ad1b5ade 100644 --- a/awx/main/tests/base.py +++ b/awx/main/tests/base.py @@ -10,6 +10,7 @@ import os import shutil import tempfile import time +from multiprocessing import Process # PyYAML import yaml @@ -23,6 +24,8 @@ from django.test.client import Client # AWX from awx.main.models import * from awx.main.backend import LDAPSettings +from awx.main.management.commands.run_callback_receiver import run_subscriber + class BaseTestMixin(object): ''' @@ -363,6 +366,14 @@ class BaseTestMixin(object): for obj in response['results']: self.assertTrue(set(obj.keys()) <= set(fields)) + def start_queue(self, consumer_port, queue_port): + self.queue_process = Process(target=run_subscriber, + args=(consumer_port, queue_port, False,)) + self.queue_process.start() + + def terminate_queue(self): + self.queue_process.terminate() + class BaseTest(BaseTestMixin, django.test.TestCase): ''' Base class for unit tests. diff --git a/awx/main/tests/commands.py b/awx/main/tests/commands.py index b25d6a04d1..6def182bcd 100644 --- a/awx/main/tests/commands.py +++ b/awx/main/tests/commands.py @@ -301,9 +301,11 @@ class CleanupJobsTest(BaseCommandMixin, BaseLiveServerTest): self.project = None self.credential = None settings.INTERNAL_API_URL = self.live_server_url + self.start_queue(settings.CALLBACK_CONSUMER_PORT, settings.CALLBACK_QUEUE_PORT) def tearDown(self): super(CleanupJobsTest, self).tearDown() + self.terminate_queue() if self.test_project_path: shutil.rmtree(self.test_project_path, True) diff --git a/awx/main/tests/inventory.py b/awx/main/tests/inventory.py index 481c9f7495..50bc04466a 100644 --- a/awx/main/tests/inventory.py +++ b/awx/main/tests/inventory.py @@ -991,7 +991,12 @@ class InventoryUpdatesTest(BaseTransactionTest): self.group = self.inventory.groups.create(name='Cloud Group') self.inventory2 = self.organization.inventories.create(name='Cloud Inventory 2') self.group2 = self.inventory2.groups.create(name='Cloud Group 2') + self.start_queue(settings.CALLBACK_CONSUMER_PORT, settings.CALLBACK_QUEUE_PORT) + def tearDown(self): + super(InventoryUpdatesTest, self).tearDown() + self.terminate_queue() + def update_inventory_source(self, group, **kwargs): inventory_source = group.inventory_source update_fields = [] diff --git a/awx/main/tests/jobs.py b/awx/main/tests/jobs.py index 1ccf853888..6f21d3ba5e 100644 --- a/awx/main/tests/jobs.py +++ b/awx/main/tests/jobs.py @@ -442,6 +442,12 @@ class BaseJobTestMixin(BaseTestMixin): def setUp(self): super(BaseJobTestMixin, self).setUp() self.populate() + #self.start_queue("ipc:///tmp/test_consumer.ipc", "ipc:///tmp/test_queue.ipc") + self.start_queue(settings.CALLBACK_CONSUMER_PORT, settings.CALLBACK_QUEUE_PORT) + + def tearDown(self): + super(BaseJobTestMixin, self).tearDown() + self.terminate_queue() class JobTemplateTest(BaseJobTestMixin, django.test.TestCase): @@ -773,6 +779,7 @@ MIDDLEWARE_CLASSES = filter(lambda x: not x.endswith('TransactionMiddleware'), @override_settings(CELERY_ALWAYS_EAGER=True, CELERY_EAGER_PROPAGATES_EXCEPTIONS=True, + CALLBACK_BYPASS_QUEUE=True, ANSIBLE_TRANSPORT='local', MIDDLEWARE_CLASSES=MIDDLEWARE_CLASSES) class JobStartCancelTest(BaseJobTestMixin, django.test.LiveServerTestCase): @@ -904,6 +911,9 @@ class JobStartCancelTest(BaseJobTestMixin, django.test.LiveServerTestCase): job = self.job_ops_east_run job.start() + # Wait for events to filter in since we are using a single consumer + time.sleep(30) + # Check that the job detail has been updated. url = reverse('api:job_detail', args=(job.pk,)) with self.current_user(self.user_sue): diff --git a/awx/main/tests/projects.py b/awx/main/tests/projects.py index f211fb143d..5a3ff9df3e 100644 --- a/awx/main/tests/projects.py +++ b/awx/main/tests/projects.py @@ -680,6 +680,11 @@ class ProjectUpdatesTest(BaseTransactionTest): def setUp(self): super(ProjectUpdatesTest, self).setUp() self.setup_users() + self.start_queue(settings.CALLBACK_CONSUMER_PORT, settings.CALLBACK_QUEUE_PORT) + + def tearDown(self): + super(ProjectUpdatesTest, self).tearDown() + self.terminate_queue() def create_project(self, **kwargs): cred_fields = ['scm_username', 'scm_password', 'scm_key_data', diff --git a/awx/main/tests/tasks.py b/awx/main/tests/tasks.py index 13aa44ec09..8bf31dc434 100644 --- a/awx/main/tests/tasks.py +++ b/awx/main/tests/tasks.py @@ -188,12 +188,14 @@ class RunJobTest(BaseCeleryTest): return args RunJob.build_args = new_build_args settings.INTERNAL_API_URL = self.live_server_url + self.start_queue(settings.CALLBACK_CONSUMER_PORT, settings.CALLBACK_QUEUE_PORT) def tearDown(self): super(RunJobTest, self).tearDown() if self.test_project_path: shutil.rmtree(self.test_project_path, True) RunJob.build_args = self.original_build_args + self.terminate_queue() def create_test_credential(self, **kwargs): opts = {