This file is indexed.

/usr/lib/python2.7/dist-packages/celery/tests/app/test_control.py is in python-celery 3.1.20-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
from __future__ import absolute_import

import warnings

from functools import wraps

from kombu.pidbox import Mailbox

from celery.app import control
from celery.utils import uuid
from celery.tests.case import AppCase


class MockMailbox(Mailbox):
    sent = []

    def _publish(self, command, *args, **kwargs):
        self.__class__.sent.append(command)

    def close(self):
        pass

    def _collect(self, *args, **kwargs):
        pass


class Control(control.Control):
    Mailbox = MockMailbox


def with_mock_broadcast(fun):

    @wraps(fun)
    def _resets(*args, **kwargs):
        MockMailbox.sent = []
        try:
            return fun(*args, **kwargs)
        finally:
            MockMailbox.sent = []
    return _resets


class test_flatten_reply(AppCase):

    def test_flatten_reply(self):
        reply = [
            {'foo@example.com': {'hello': 10}},
            {'foo@example.com': {'hello': 20}},
            {'bar@example.com': {'hello': 30}}
        ]
        with warnings.catch_warnings(record=True) as w:
            nodes = control.flatten_reply(reply)
            self.assertIn(
                'multiple replies',
                str(w[-1].message),
            )
            self.assertIn('foo@example.com', nodes)
            self.assertIn('bar@example.com', nodes)


class test_inspect(AppCase):

    def setup(self):
        self.c = Control(app=self.app)
        self.prev, self.app.control = self.app.control, self.c
        self.i = self.c.inspect()

    def test_prepare_reply(self):
        self.assertDictEqual(self.i._prepare([{'w1': {'ok': 1}},
                                              {'w2': {'ok': 1}}]),
                             {'w1': {'ok': 1}, 'w2': {'ok': 1}})

        i = self.c.inspect(destination='w1')
        self.assertEqual(i._prepare([{'w1': {'ok': 1}}]),
                         {'ok': 1})

    @with_mock_broadcast
    def test_active(self):
        self.i.active()
        self.assertIn('dump_active', MockMailbox.sent)

    @with_mock_broadcast
    def test_clock(self):
        self.i.clock()
        self.assertIn('clock', MockMailbox.sent)

    @with_mock_broadcast
    def test_conf(self):
        self.i.conf()
        self.assertIn('dump_conf', MockMailbox.sent)

    @with_mock_broadcast
    def test_hello(self):
        self.i.hello('george@vandelay.com')
        self.assertIn('hello', MockMailbox.sent)

    @with_mock_broadcast
    def test_memsample(self):
        self.i.memsample()
        self.assertIn('memsample', MockMailbox.sent)

    @with_mock_broadcast
    def test_memdump(self):
        self.i.memdump()
        self.assertIn('memdump', MockMailbox.sent)

    @with_mock_broadcast
    def test_objgraph(self):
        self.i.objgraph()
        self.assertIn('objgraph', MockMailbox.sent)

    @with_mock_broadcast
    def test_scheduled(self):
        self.i.scheduled()
        self.assertIn('dump_schedule', MockMailbox.sent)

    @with_mock_broadcast
    def test_reserved(self):
        self.i.reserved()
        self.assertIn('dump_reserved', MockMailbox.sent)

    @with_mock_broadcast
    def test_stats(self):
        self.i.stats()
        self.assertIn('stats', MockMailbox.sent)

    @with_mock_broadcast
    def test_revoked(self):
        self.i.revoked()
        self.assertIn('dump_revoked', MockMailbox.sent)

    @with_mock_broadcast
    def test_tasks(self):
        self.i.registered()
        self.assertIn('dump_tasks', MockMailbox.sent)

    @with_mock_broadcast
    def test_ping(self):
        self.i.ping()
        self.assertIn('ping', MockMailbox.sent)

    @with_mock_broadcast
    def test_active_queues(self):
        self.i.active_queues()
        self.assertIn('active_queues', MockMailbox.sent)

    @with_mock_broadcast
    def test_report(self):
        self.i.report()
        self.assertIn('report', MockMailbox.sent)


class test_Broadcast(AppCase):

    def setup(self):
        self.control = Control(app=self.app)
        self.app.control = self.control

        @self.app.task(shared=False)
        def mytask():
            pass
        self.mytask = mytask

    def test_purge(self):
        self.control.purge()

    @with_mock_broadcast
    def test_broadcast(self):
        self.control.broadcast('foobarbaz', arguments=[])
        self.assertIn('foobarbaz', MockMailbox.sent)

    @with_mock_broadcast
    def test_broadcast_limit(self):
        self.control.broadcast(
            'foobarbaz1', arguments=[], limit=None, destination=[1, 2, 3],
        )
        self.assertIn('foobarbaz1', MockMailbox.sent)

    @with_mock_broadcast
    def test_broadcast_validate(self):
        with self.assertRaises(ValueError):
            self.control.broadcast('foobarbaz2',
                                   destination='foo')

    @with_mock_broadcast
    def test_rate_limit(self):
        self.control.rate_limit(self.mytask.name, '100/m')
        self.assertIn('rate_limit', MockMailbox.sent)

    @with_mock_broadcast
    def test_time_limit(self):
        self.control.time_limit(self.mytask.name, soft=10, hard=20)
        self.assertIn('time_limit', MockMailbox.sent)

    @with_mock_broadcast
    def test_add_consumer(self):
        self.control.add_consumer('foo')
        self.assertIn('add_consumer', MockMailbox.sent)

    @with_mock_broadcast
    def test_cancel_consumer(self):
        self.control.cancel_consumer('foo')
        self.assertIn('cancel_consumer', MockMailbox.sent)

    @with_mock_broadcast
    def test_enable_events(self):
        self.control.enable_events()
        self.assertIn('enable_events', MockMailbox.sent)

    @with_mock_broadcast
    def test_disable_events(self):
        self.control.disable_events()
        self.assertIn('disable_events', MockMailbox.sent)

    @with_mock_broadcast
    def test_revoke(self):
        self.control.revoke('foozbaaz')
        self.assertIn('revoke', MockMailbox.sent)

    @with_mock_broadcast
    def test_ping(self):
        self.control.ping()
        self.assertIn('ping', MockMailbox.sent)

    @with_mock_broadcast
    def test_election(self):
        self.control.election('some_id', 'topic', 'action')
        self.assertIn('election', MockMailbox.sent)

    @with_mock_broadcast
    def test_pool_grow(self):
        self.control.pool_grow(2)
        self.assertIn('pool_grow', MockMailbox.sent)

    @with_mock_broadcast
    def test_pool_shrink(self):
        self.control.pool_shrink(2)
        self.assertIn('pool_shrink', MockMailbox.sent)

    @with_mock_broadcast
    def test_revoke_from_result(self):
        self.app.AsyncResult('foozbazzbar').revoke()
        self.assertIn('revoke', MockMailbox.sent)

    @with_mock_broadcast
    def test_revoke_from_resultset(self):
        r = self.app.GroupResult(uuid(),
                                 [self.app.AsyncResult(x)
                                  for x in [uuid() for i in range(10)]])
        r.revoke()
        self.assertIn('revoke', MockMailbox.sent)