Exemplo n.º 1
0
 def test_override(self):
     options = VumiOptions()
     options.parseOptions(['--hostname', 'blah', '--username', 'haxor'])
     self.assertEqual({}, options.opts)
     self.assertEqual(
         dict(VumiOptions.default_vumi_options,
              username='******',
              hostname='blah'), options.vumi_options)
Exemplo n.º 2
0
 def test_config_file(self):
     options = VumiOptions()
     self.mk_config_file('vumi', ["username: foo", "password: bar"])
     options.parseOptions(['--vumi-config', self.config_file['vumi']])
     self.assertEqual({}, options.opts)
     self.assertEqual(dict(VumiOptions.default_vumi_options,
                           username='******', password='******'),
                      options.vumi_options)
Exemplo n.º 3
0
 def test_config_file_override(self):
     self.mk_config_file('vumi', ["username: foo", "password: bar"])
     options = VumiOptions()
     options.parseOptions(['--vumi-config', self.config_file['vumi'],
                           '--hostname', 'blah',
                           '--username', 'haxor'])
     self.assertEqual({}, options.opts)
     self.assertEqual(dict(VumiOptions.default_vumi_options,
                           username='******', password='******',
                           hostname='blah'),
                      options.vumi_options)
Exemplo n.º 4
0
 def test_defaults(self):
     options = VumiOptions()
     options.parseOptions([])
     self.assertEqual({}, options.opts)
     self.assertEqual(VumiOptions.default_vumi_options,
                      options.vumi_options)
Exemplo n.º 5
0
def run_bench(loops):
    opts = VumiOptions()
    opts.postOptions()
    worker_creator = WorkerCreator(opts.vumi_options)

    app = worker_creator.create_worker_by_class(
        BenchApp, {
            "transport_name": "dummy",
            "javascript": """
            api.on_inbound_message = function(command) {
                this.request('outbound.reply_to', {
                    content: 'reply',
                    in_reply_to: command.msg.message_id,
                },
                function (reply) {
                    this.done();
                });
            };
        """,
            "sandbox": {
                'log': {
                    'cls': 'vumi.application.sandbox.LoggingResource',
                },
                'outbound': {
                    'cls': 'vumi.application.sandbox.OutboundResource',
                },
            },
        })

    transport = worker_creator.create_worker_by_class(
        BenchTransport, {
            "transport_name": "dummy",
        })

    yield transport.startService()
    log.msg("Waiting for transport ...")
    yield BenchTransport.WORKER_QUEUE.get()

    yield app.startService()
    log.msg("Waiting for worker ...")
    yield BenchApp.WORKER_QUEUE.get()

    print "Starting %d loops ..." % (loops, )
    timer = Timer()
    for i in range(loops):
        with timer:
            transport.publish_message(
                content="Hi!",
                to_addr="+1234",
                from_addr="+5678",
                transport_type="ussd",
            )
            reply = yield transport.message_queue.get()
            log.msg("Reply ID: %s" % reply['message_id'])

    print "Total time: %.2f" % timer.total()
    print "Time per message: %g" % timer.mean()
    print "  max: %g, min: %g" % (timer.max(), timer.min())
    print "  loops: %d" % timer.loops()

    yield transport.stopService()
    yield app.stopService()
    reactor.stop()