Ejemplo n.º 1
0
    def test_make_worker_with_threadpool_size(self):
        """
        The reactor threadpool can be resized with a command line option.
        """
        from twisted.internet import reactor

        old_maxthreads = reactor.getThreadPool().max
        self.add_cleanup(reactor.suggestThreadPoolSize, old_maxthreads)
        # Explicitly set the threadpool size to something different from the
        # value we're testing with.
        reactor.suggestThreadPoolSize(5)

        self.mk_config_file('worker', ["transport_name: sphex"])
        maker = VumiWorkerServiceMaker()

        # By default, we don't touch the threadpool.
        options = StartWorkerOptions()
        options.parseOptions([
            '--worker-class', 'vumi.demos.words.EchoWorker',
            '--config', self.config_file['worker'],
        ])
        worker = maker.makeService(options)
        self.assertEqual({'transport_name': 'sphex'}, worker.config)
        self.assertEqual(reactor.getThreadPool().max, 5)

        # If asked, we set the threadpool's maximum size.
        options_mt = StartWorkerOptions()
        options_mt.parseOptions([
            '--worker-class', 'vumi.demos.words.EchoWorker',
            '--config', self.config_file['worker'],
            '--maxthreads', '2',
        ])
        worker = maker.makeService(options_mt)
        self.assertEqual({'transport_name': 'sphex'}, worker.config)
        self.assertEqual(reactor.getThreadPool().max, 2)
Ejemplo n.º 2
0
 def test_make_worker(self):
     self.mk_config_file('worker', ["transport_name: sphex"])
     options = StartWorkerOptions()
     options.parseOptions(['--worker-class', 'vumi.demos.words.EchoWorker',
                           '--config', self.config_file['worker'],
                           ])
     maker = VumiWorkerServiceMaker()
     worker = maker.makeService(options)
     self.assertEqual({'transport_name': 'sphex'}, worker.config)
Ejemplo n.º 3
0
 def test_make_worker(self):
     self.mk_config_file('worker', ["transport_name: sphex"])
     options = StartWorkerOptions()
     options.parseOptions(['--worker-class', 'vumi.demos.words.EchoWorker',
                           '--config', self.config_file['worker'],
                           ])
     maker = VumiWorkerServiceMaker()
     worker = maker.makeService(options)
     self.assertEqual({'transport_name': 'sphex'}, worker.config)
Ejemplo n.º 4
0
    def test_make_worker_with_threadpool_size(self):
        """
        The reactor threadpool can be resized with a command line option.
        """
        from twisted.internet import reactor

        old_maxthreads = reactor.getThreadPool().max
        self.add_cleanup(reactor.suggestThreadPoolSize, old_maxthreads)
        # Explicitly set the threadpool size to something different from the
        # value we're testing with.
        reactor.suggestThreadPoolSize(5)

        self.mk_config_file('worker', ["transport_name: sphex"])
        maker = VumiWorkerServiceMaker()

        # By default, we don't touch the threadpool.
        options = StartWorkerOptions()
        options.parseOptions([
            '--worker-class',
            'vumi.demos.words.EchoWorker',
            '--config',
            self.config_file['worker'],
        ])
        worker = maker.makeService(options)
        self.assertEqual({'transport_name': 'sphex'}, worker.config)
        self.assertEqual(reactor.getThreadPool().max, 5)

        # If asked, we set the threadpool's maximum size.
        options_mt = StartWorkerOptions()
        options_mt.parseOptions([
            '--worker-class',
            'vumi.demos.words.EchoWorker',
            '--config',
            self.config_file['worker'],
            '--maxthreads',
            '2',
        ])
        worker = maker.makeService(options_mt)
        self.assertEqual({'transport_name': 'sphex'}, worker.config)
        self.assertEqual(reactor.getThreadPool().max, 2)
Ejemplo n.º 5
0
    def test_make_worker_with_sentry(self):
        services = []
        dummy_service = DummyService()

        def service(*a, **kw):
            services.append((a, kw))
            return dummy_service

        self.patch(servicemaker, 'SentryLoggerService', service)
        self.mk_config_file('worker', ["transport_name: sphex"])
        options = StartWorkerOptions()
        options.parseOptions(['--worker-class', 'vumi.demos.words.EchoWorker',
                              '--config', self.config_file['worker'],
                              '--sentry', 'http://*****:*****@example.com/2/',
                              ])
        maker = VumiWorkerServiceMaker()
        worker = maker.makeService(options)
        self.assertEqual(services, [
                (('http://*****:*****@example.com/2/',
                  'echoworker',
                  'global:echoworker'), {})
        ])
        self.assertTrue(dummy_service in worker.services)
Ejemplo n.º 6
0
    def test_make_worker_with_sentry(self):
        services = []
        dummy_service = DummyService()

        def service(*a, **kw):
            services.append((a, kw))
            return dummy_service

        self.patch(servicemaker, 'SentryLoggerService', service)
        self.mk_config_file('worker', ["transport_name: sphex"])
        options = StartWorkerOptions()
        options.parseOptions([
            '--worker-class',
            'vumi.demos.words.EchoWorker',
            '--config',
            self.config_file['worker'],
            '--sentry',
            'http://*****:*****@example.com/2/',
        ])
        maker = VumiWorkerServiceMaker()
        worker = maker.makeService(options)
        self.assertEqual(services, [(('http://*****:*****@example.com/2/',
                                      'echoworker', 'global:echoworker'), {})])
        self.assertTrue(dummy_service in worker.services)
Ejemplo n.º 7
0
"""Plugins for starting Vumi workers from twistd."""

from vumi.servicemaker import (VumiWorkerServiceMaker,
                               DeprecatedStartWorkerServiceMaker)

# Having instances of IServiceMaker present magically announces the
# service makers to twistd.
# See: http://twistedmatrix.com/documents/current/core/howto/tap.html
vumi_worker = VumiWorkerServiceMaker()
start_worker = DeprecatedStartWorkerServiceMaker()