test_canvas.py 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680
  1. from __future__ import absolute_import, unicode_literals
  2. import pytest
  3. from case import MagicMock, Mock
  4. from celery._state import _task_stack
  5. from celery.canvas import (
  6. Signature,
  7. chain,
  8. _chain,
  9. group,
  10. chord,
  11. signature,
  12. xmap,
  13. xstarmap,
  14. chunks,
  15. _maybe_group,
  16. maybe_signature,
  17. maybe_unroll_group,
  18. )
  19. from celery.result import AsyncResult, GroupResult, EagerResult
  20. SIG = Signature({
  21. 'task': 'TASK',
  22. 'args': ('A1',),
  23. 'kwargs': {'K1': 'V1'},
  24. 'options': {'task_id': 'TASK_ID'},
  25. 'subtask_type': ''},
  26. )
  27. class test_maybe_unroll_group:
  28. def test_when_no_len_and_no_length_hint(self):
  29. g = MagicMock(name='group')
  30. g.tasks.__len__.side_effect = TypeError()
  31. g.tasks.__length_hint__ = Mock()
  32. g.tasks.__length_hint__.return_value = 0
  33. assert maybe_unroll_group(g) is g
  34. g.tasks.__length_hint__.side_effect = AttributeError()
  35. assert maybe_unroll_group(g) is g
  36. class CanvasCase:
  37. def setup(self):
  38. @self.app.task(shared=False)
  39. def add(x, y):
  40. return x + y
  41. self.add = add
  42. @self.app.task(shared=False)
  43. def mul(x, y):
  44. return x * y
  45. self.mul = mul
  46. @self.app.task(shared=False)
  47. def div(x, y):
  48. return x / y
  49. self.div = div
  50. class test_Signature(CanvasCase):
  51. def test_getitem_property_class(self):
  52. assert Signature.task
  53. assert Signature.args
  54. assert Signature.kwargs
  55. assert Signature.options
  56. assert Signature.subtask_type
  57. def test_getitem_property(self):
  58. assert SIG.task == 'TASK'
  59. assert SIG.args == ('A1',)
  60. assert SIG.kwargs == {'K1': 'V1'}
  61. assert SIG.options == {'task_id': 'TASK_ID'}
  62. assert SIG.subtask_type == ''
  63. def test_call(self):
  64. x = Signature('foo', (1, 2), {'arg1': 33}, app=self.app)
  65. x.type = Mock(name='type')
  66. x(3, 4, arg2=66)
  67. x.type.assert_called_with(3, 4, 1, 2, arg1=33, arg2=66)
  68. def test_link_on_scalar(self):
  69. x = Signature('TASK', link=Signature('B'))
  70. assert x.options['link']
  71. x.link(Signature('C'))
  72. assert isinstance(x.options['link'], list)
  73. assert Signature('B') in x.options['link']
  74. assert Signature('C') in x.options['link']
  75. def test_json(self):
  76. x = Signature('TASK', link=Signature('B', app=self.app), app=self.app)
  77. assert x.__json__() == dict(x)
  78. @pytest.mark.usefixtures('depends_on_current_app')
  79. def test_reduce(self):
  80. x = Signature('TASK', (2, 4), app=self.app)
  81. fun, args = x.__reduce__()
  82. assert fun(*args) == x
  83. def test_replace(self):
  84. x = Signature('TASK', ('A'), {})
  85. assert x.replace(args=('B',)).args == ('B',)
  86. assert x.replace(kwargs={'FOO': 'BAR'}).kwargs == {
  87. 'FOO': 'BAR',
  88. }
  89. assert x.replace(options={'task_id': '123'}).options == {
  90. 'task_id': '123',
  91. }
  92. def test_set(self):
  93. assert Signature('TASK', x=1).set(task_id='2').options == {
  94. 'x': 1, 'task_id': '2',
  95. }
  96. def test_link(self):
  97. x = signature(SIG)
  98. x.link(SIG)
  99. x.link(SIG)
  100. assert SIG in x.options['link']
  101. assert len(x.options['link']) == 1
  102. def test_link_error(self):
  103. x = signature(SIG)
  104. x.link_error(SIG)
  105. x.link_error(SIG)
  106. assert SIG in x.options['link_error']
  107. assert len(x.options['link_error']) == 1
  108. def test_flatten_links(self):
  109. tasks = [self.add.s(2, 2), self.mul.s(4), self.div.s(2)]
  110. tasks[0].link(tasks[1])
  111. tasks[1].link(tasks[2])
  112. assert tasks[0].flatten_links() == tasks
  113. def test_OR(self):
  114. x = self.add.s(2, 2) | self.mul.s(4)
  115. assert isinstance(x, _chain)
  116. y = self.add.s(4, 4) | self.div.s(2)
  117. z = x | y
  118. assert isinstance(y, _chain)
  119. assert isinstance(z, _chain)
  120. assert len(z.tasks) == 4
  121. with pytest.raises(TypeError):
  122. x | 10
  123. ax = self.add.s(2, 2) | (self.add.s(4) | self.add.s(8))
  124. assert isinstance(ax, _chain)
  125. assert len(ax.tasks), 3 == 'consolidates chain to chain'
  126. def test_INVERT(self):
  127. x = self.add.s(2, 2)
  128. x.apply_async = Mock()
  129. x.apply_async.return_value = Mock()
  130. x.apply_async.return_value.get = Mock()
  131. x.apply_async.return_value.get.return_value = 4
  132. assert ~x == 4
  133. x.apply_async.assert_called()
  134. def test_merge_immutable(self):
  135. x = self.add.si(2, 2, foo=1)
  136. args, kwargs, options = x._merge((4,), {'bar': 2}, {'task_id': 3})
  137. assert args == (2, 2)
  138. assert kwargs == {'foo': 1}
  139. assert options == {'task_id': 3}
  140. def test_set_immutable(self):
  141. x = self.add.s(2, 2)
  142. assert not x.immutable
  143. x.set(immutable=True)
  144. assert x.immutable
  145. x.set(immutable=False)
  146. assert not x.immutable
  147. def test_election(self):
  148. x = self.add.s(2, 2)
  149. x.freeze('foo')
  150. x.type.app.control = Mock()
  151. r = x.election()
  152. x.type.app.control.election.assert_called()
  153. assert r.id == 'foo'
  154. def test_AsyncResult_when_not_registered(self):
  155. s = signature('xxx.not.registered', app=self.app)
  156. assert s.AsyncResult
  157. def test_apply_async_when_not_registered(self):
  158. s = signature('xxx.not.registered', app=self.app)
  159. assert s._apply_async
  160. class test_xmap_xstarmap(CanvasCase):
  161. def test_apply(self):
  162. for type, attr in [(xmap, 'map'), (xstarmap, 'starmap')]:
  163. args = [(i, i) for i in range(10)]
  164. s = getattr(self.add, attr)(args)
  165. s.type = Mock()
  166. s.apply_async(foo=1)
  167. s.type.apply_async.assert_called_with(
  168. (), {'task': self.add.s(), 'it': args}, foo=1,
  169. route_name=self.add.name,
  170. )
  171. assert type.from_dict(dict(s)) == s
  172. assert repr(s)
  173. class test_chunks(CanvasCase):
  174. def test_chunks(self):
  175. x = self.add.chunks(range(100), 10)
  176. assert dict(chunks.from_dict(dict(x), app=self.app)) == dict(x)
  177. assert x.group()
  178. assert len(x.group().tasks) == 10
  179. x.group = Mock()
  180. gr = x.group.return_value = Mock()
  181. x.apply_async()
  182. gr.apply_async.assert_called_with((), {}, route_name=self.add.name)
  183. gr.apply_async.reset_mock()
  184. x()
  185. gr.apply_async.assert_called_with((), {}, route_name=self.add.name)
  186. self.app.conf.task_always_eager = True
  187. chunks.apply_chunks(app=self.app, **x['kwargs'])
  188. class test_chain(CanvasCase):
  189. def test_clone_preserves_state(self):
  190. x = chain(self.add.s(i, i) for i in range(10))
  191. assert x.clone().tasks == x.tasks
  192. assert x.clone().kwargs == x.kwargs
  193. assert x.clone().args == x.args
  194. def test_repr(self):
  195. x = self.add.s(2, 2) | self.add.s(2)
  196. assert repr(x) == '%s(2, 2) | add(2)' % (self.add.name,)
  197. def test_apply_async(self):
  198. c = self.add.s(2, 2) | self.add.s(4) | self.add.s(8)
  199. result = c.apply_async()
  200. assert result.parent
  201. assert result.parent.parent
  202. assert result.parent.parent.parent is None
  203. def test_splices_chains(self):
  204. c = chain(
  205. self.add.s(5, 5),
  206. chain(self.add.s(6), self.add.s(7), self.add.s(8), app=self.app),
  207. app=self.app,
  208. )
  209. c.freeze()
  210. tasks, _ = c._frozen
  211. assert len(tasks) == 4
  212. def test_from_dict_no_tasks(self):
  213. assert chain.from_dict(dict(chain(app=self.app)), app=self.app)
  214. @pytest.mark.usefixtures('depends_on_current_app')
  215. def test_app_falls_back_to_default(self):
  216. from celery._state import current_app
  217. assert chain().app is current_app
  218. def test_handles_dicts(self):
  219. c = chain(
  220. self.add.s(5, 5), dict(self.add.s(8)), app=self.app,
  221. )
  222. c.freeze()
  223. tasks, _ = c._frozen
  224. for task in tasks:
  225. assert isinstance(task, Signature)
  226. assert task.app is self.app
  227. def test_group_to_chord(self):
  228. c = (
  229. self.add.s(5) |
  230. group([self.add.s(i, i) for i in range(5)], app=self.app) |
  231. self.add.s(10) |
  232. self.add.s(20) |
  233. self.add.s(30)
  234. )
  235. c._use_link = True
  236. tasks, results = c.prepare_steps((), c.tasks)
  237. assert tasks[-1].args[0] == 5
  238. assert isinstance(tasks[-2], chord)
  239. assert len(tasks[-2].tasks) == 5
  240. body = tasks[-2].body
  241. assert len(body.tasks) == 3
  242. assert body.tasks[0].args[0] == 10
  243. assert body.tasks[1].args[0] == 20
  244. assert body.tasks[2].args[0] == 30
  245. c2 = self.add.s(2, 2) | group(self.add.s(i, i) for i in range(10))
  246. c2._use_link = True
  247. tasks2, _ = c2.prepare_steps((), c2.tasks)
  248. assert isinstance(tasks2[0], group)
  249. def test_group_to_chord__protocol_2__or(self):
  250. c = (
  251. group([self.add.s(i, i) for i in range(5)], app=self.app) |
  252. self.add.s(10) |
  253. self.add.s(20) |
  254. self.add.s(30)
  255. )
  256. assert isinstance(c, chord)
  257. def test_group_to_chord__protocol_2(self):
  258. c = chain(
  259. group([self.add.s(i, i) for i in range(5)], app=self.app),
  260. self.add.s(10),
  261. self.add.s(20),
  262. self.add.s(30)
  263. )
  264. assert isinstance(c, chord)
  265. assert isinstance(c.body, _chain)
  266. assert len(c.body.tasks) == 3
  267. c2 = self.add.s(2, 2) | group(self.add.s(i, i) for i in range(10))
  268. c2._use_link = False
  269. tasks2, _ = c2.prepare_steps((), c2.tasks)
  270. assert isinstance(tasks2[0], group)
  271. def test_apply_options(self):
  272. class static(Signature):
  273. def clone(self, *args, **kwargs):
  274. return self
  275. def s(*args, **kwargs):
  276. return static(self.add, args, kwargs, type=self.add, app=self.app)
  277. c = s(2, 2) | s(4) | s(8)
  278. r1 = c.apply_async(task_id='some_id')
  279. assert r1.id == 'some_id'
  280. c.apply_async(group_id='some_group_id')
  281. assert c.tasks[-1].options['group_id'] == 'some_group_id'
  282. c.apply_async(chord='some_chord_id')
  283. assert c.tasks[-1].options['chord'] == 'some_chord_id'
  284. c.apply_async(link=[s(32)])
  285. assert c.tasks[-1].options['link'] == [s(32)]
  286. c.apply_async(link_error=[s('error')])
  287. for task in c.tasks:
  288. assert task.options['link_error'] == [s('error')]
  289. def test_reverse(self):
  290. x = self.add.s(2, 2) | self.add.s(2)
  291. assert isinstance(signature(x), _chain)
  292. assert isinstance(signature(dict(x)), _chain)
  293. def test_always_eager(self):
  294. self.app.conf.task_always_eager = True
  295. assert ~(self.add.s(4, 4) | self.add.s(8)) == 16
  296. def test_apply(self):
  297. x = chain(self.add.s(4, 4), self.add.s(8), self.add.s(10))
  298. res = x.apply()
  299. assert isinstance(res, EagerResult)
  300. assert res.get() == 26
  301. assert res.parent.get() == 16
  302. assert res.parent.parent.get() == 8
  303. assert res.parent.parent.parent is None
  304. def test_empty_chain_returns_none(self):
  305. assert chain(app=self.app)() is None
  306. assert chain(app=self.app).apply_async() is None
  307. def test_call_no_tasks(self):
  308. x = chain()
  309. assert not x()
  310. def test_call_with_tasks(self):
  311. x = self.add.s(2, 2) | self.add.s(4)
  312. x.apply_async = Mock()
  313. x(2, 2, foo=1)
  314. x.apply_async.assert_called_with((2, 2), {'foo': 1})
  315. def test_from_dict_no_args__with_args(self):
  316. x = dict(self.add.s(2, 2) | self.add.s(4))
  317. x['args'] = None
  318. assert isinstance(chain.from_dict(x), _chain)
  319. x['args'] = (2,)
  320. assert isinstance(chain.from_dict(x), _chain)
  321. def test_accepts_generator_argument(self):
  322. x = chain(self.add.s(i) for i in range(10))
  323. assert x.tasks[0].type, self.add
  324. assert x.type
  325. def test_chord_sets_result_parent(self):
  326. g = (self.add.s(0, 0) |
  327. group(self.add.s(i, i) for i in range(1, 10)) |
  328. self.add.s(2, 2) |
  329. self.add.s(4, 4))
  330. res = g.freeze()
  331. assert isinstance(res, AsyncResult)
  332. assert not isinstance(res, GroupResult)
  333. assert isinstance(res.parent, AsyncResult)
  334. assert not isinstance(res.parent, GroupResult)
  335. assert isinstance(res.parent.parent, GroupResult)
  336. assert isinstance(res.parent.parent.parent, AsyncResult)
  337. assert not isinstance(res.parent.parent.parent, GroupResult)
  338. assert res.parent.parent.parent.parent is None
  339. seen = set()
  340. node = res
  341. while node:
  342. assert node.id not in seen
  343. seen.add(node.id)
  344. node = node.parent
  345. class test_group(CanvasCase):
  346. def test_repr(self):
  347. x = group([self.add.s(2, 2), self.add.s(4, 4)])
  348. assert repr(x)
  349. def test_reverse(self):
  350. x = group([self.add.s(2, 2), self.add.s(4, 4)])
  351. assert isinstance(signature(x), group)
  352. assert isinstance(signature(dict(x)), group)
  353. def test_cannot_link_on_group(self):
  354. x = group([self.add.s(2, 2), self.add.s(4, 4)])
  355. with pytest.raises(TypeError):
  356. x.apply_async(link=self.add.s(2, 2))
  357. def test_cannot_link_error_on_group(self):
  358. x = group([self.add.s(2, 2), self.add.s(4, 4)])
  359. with pytest.raises(TypeError):
  360. x.apply_async(link_error=self.add.s(2, 2))
  361. def test_group_with_group_argument(self):
  362. g1 = group(self.add.s(2, 2), self.add.s(4, 4), app=self.app)
  363. g2 = group(g1, app=self.app)
  364. assert g2.tasks is g1.tasks
  365. def test_maybe_group_sig(self):
  366. assert _maybe_group(self.add.s(2, 2), self.app) == [self.add.s(2, 2)]
  367. def test_apply(self):
  368. x = group([self.add.s(4, 4), self.add.s(8, 8)])
  369. res = x.apply()
  370. assert res.get(), [8 == 16]
  371. def test_apply_async(self):
  372. x = group([self.add.s(4, 4), self.add.s(8, 8)])
  373. x.apply_async()
  374. def test_prepare_with_dict(self):
  375. x = group([self.add.s(4, 4), dict(self.add.s(8, 8))], app=self.app)
  376. x.apply_async()
  377. def test_group_in_group(self):
  378. g1 = group(self.add.s(2, 2), self.add.s(4, 4), app=self.app)
  379. g2 = group(self.add.s(8, 8), g1, self.add.s(16, 16), app=self.app)
  380. g2.apply_async()
  381. def test_set_immutable(self):
  382. g1 = group(Mock(name='t1'), Mock(name='t2'), app=self.app)
  383. g1.set_immutable(True)
  384. for task in g1.tasks:
  385. task.set_immutable.assert_called_with(True)
  386. def test_link(self):
  387. g1 = group(Mock(name='t1'), Mock(name='t2'), app=self.app)
  388. sig = Mock(name='sig')
  389. g1.link(sig)
  390. g1.tasks[0].link.assert_called_with(sig.clone().set(immutable=True))
  391. def test_link_error(self):
  392. g1 = group(Mock(name='t1'), Mock(name='t2'), app=self.app)
  393. sig = Mock(name='sig')
  394. g1.link_error(sig)
  395. g1.tasks[0].link_error.assert_called_with(
  396. sig.clone().set(immutable=True),
  397. )
  398. def test_apply_empty(self):
  399. x = group(app=self.app)
  400. x.apply()
  401. res = x.apply_async()
  402. assert res
  403. assert not res.results
  404. def test_apply_async_with_parent(self):
  405. _task_stack.push(self.add)
  406. try:
  407. self.add.push_request(called_directly=False)
  408. try:
  409. assert not self.add.request.children
  410. x = group([self.add.s(4, 4), self.add.s(8, 8)])
  411. res = x()
  412. assert self.add.request.children
  413. assert res in self.add.request.children
  414. assert len(self.add.request.children) == 1
  415. finally:
  416. self.add.pop_request()
  417. finally:
  418. _task_stack.pop()
  419. def test_from_dict(self):
  420. x = group([self.add.s(2, 2), self.add.s(4, 4)])
  421. x['args'] = (2, 2)
  422. assert group.from_dict(dict(x))
  423. x['args'] = None
  424. assert group.from_dict(dict(x))
  425. def test_call_empty_group(self):
  426. x = group(app=self.app)
  427. assert not len(x())
  428. x.delay()
  429. x.apply_async()
  430. x()
  431. def test_skew(self):
  432. g = group([self.add.s(i, i) for i in range(10)])
  433. g.skew(start=1, stop=10, step=1)
  434. for i, task in enumerate(g.tasks):
  435. assert task.options['countdown'] == i + 1
  436. def test_iter(self):
  437. g = group([self.add.s(i, i) for i in range(10)])
  438. assert list(iter(g)) == list(g.keys())
  439. @staticmethod
  440. def helper_test_get_delay(result):
  441. import time
  442. t0 = time.time()
  443. while not result.ready():
  444. time.sleep(0.01)
  445. if time.time() - t0 > 1:
  446. return None
  447. return result.get()
  448. def test_kwargs_direct(self):
  449. res = [self.add(x=1, y=1), self.add(x=1, y=1)]
  450. assert res == [2, 2]
  451. def test_kwargs_apply(self):
  452. x = group([self.add.s(), self.add.s()])
  453. res = x.apply(kwargs=dict(x=1, y=1)).get()
  454. assert res == [2, 2]
  455. def test_kwargs_apply_async(self):
  456. self.app.conf.task_always_eager = True
  457. x = group([self.add.s(), self.add.s()])
  458. res = self.helper_test_get_delay(x.apply_async(kwargs=dict(x=1, y=1)))
  459. assert res == [2, 2]
  460. def test_kwargs_delay(self):
  461. self.app.conf.task_always_eager = True
  462. x = group([self.add.s(), self.add.s()])
  463. res = self.helper_test_get_delay(x.delay(x=1, y=1))
  464. assert res == [2, 2]
  465. def test_kwargs_delay_partial(self):
  466. self.app.conf.task_always_eager = True
  467. x = group([self.add.s(1), self.add.s(x=1)])
  468. res = self.helper_test_get_delay(x.delay(y=1))
  469. assert res == [2, 2]
  470. class test_chord(CanvasCase):
  471. def test_reverse(self):
  472. x = chord([self.add.s(2, 2), self.add.s(4, 4)], body=self.mul.s(4))
  473. assert isinstance(signature(x), chord)
  474. assert isinstance(signature(dict(x)), chord)
  475. def test_clone_clones_body(self):
  476. x = chord([self.add.s(2, 2), self.add.s(4, 4)], body=self.mul.s(4))
  477. y = x.clone()
  478. assert x.kwargs['body'] is not y.kwargs['body']
  479. y.kwargs.pop('body')
  480. z = y.clone()
  481. assert z.kwargs.get('body') is None
  482. def test_argument_is_group(self):
  483. x = chord(group(self.add.s(2, 2), self.add.s(4, 4), app=self.app))
  484. assert x.tasks
  485. def test_app_when_app(self):
  486. app = Mock(name='app')
  487. x = chord([self.add.s(4, 4)], app=app)
  488. assert x.app is app
  489. def test_app_when_app_in_task(self):
  490. t1 = Mock(name='t1')
  491. t2 = Mock(name='t2')
  492. x = chord([t1, self.add.s(4, 4)])
  493. assert x.app is x.tasks[0].app
  494. t1.app = None
  495. x = chord([t1], body=t2)
  496. assert x.app is t2._app
  497. def test_app_when_header_is_empty(self):
  498. x = chord([], self.add.s(4, 4))
  499. assert x.app is self.add.app
  500. @pytest.mark.usefixtures('depends_on_current_app')
  501. def test_app_fallback_to_current(self):
  502. from celery._state import current_app
  503. t1 = Mock(name='t1')
  504. t1.app = t1._app = None
  505. x = chord([t1], body=t1)
  506. assert x.app is current_app
  507. def test_set_immutable(self):
  508. x = chord([Mock(name='t1'), Mock(name='t2')], app=self.app)
  509. x.set_immutable(True)
  510. def test_links_to_body(self):
  511. x = chord([self.add.s(2, 2), self.add.s(4, 4)], body=self.mul.s(4))
  512. x.link(self.div.s(2))
  513. assert not x.options.get('link')
  514. assert x.kwargs['body'].options['link']
  515. x.link_error(self.div.s(2))
  516. assert not x.options.get('link_error')
  517. assert x.kwargs['body'].options['link_error']
  518. assert x.tasks
  519. assert x.body
  520. def test_repr(self):
  521. x = chord([self.add.s(2, 2), self.add.s(4, 4)], body=self.mul.s(4))
  522. assert repr(x)
  523. x.kwargs['body'] = None
  524. assert 'without body' in repr(x)
  525. def test_freeze_tasks_is_not_group(self):
  526. x = chord([self.add.s(2, 2)], body=self.add.s(), app=self.app)
  527. x.freeze()
  528. x.tasks = [self.add.s(2, 2)]
  529. x.freeze()
  530. def test_apply_async_task_in_chained_chords(self):
  531. x = chain(
  532. chord([self.add.si(1, 2)], body=self.mul.s(4), app=self.app),
  533. chord([self.add.si(3, 4)], body=self.mul.s(4), app=self.app)
  534. )
  535. x.apply_async()
  536. def test_apply_async_task_in_nested_chords(self):
  537. x = chord(
  538. [
  539. chord([self.add.si(5, 6)], body=self.mul.s(4), app=self.app),
  540. ],
  541. body=self.mul.s(4),
  542. app=self.app
  543. )
  544. x.apply_async()
  545. class test_maybe_signature(CanvasCase):
  546. def test_is_None(self):
  547. assert maybe_signature(None, app=self.app) is None
  548. def test_is_dict(self):
  549. assert isinstance(maybe_signature(dict(self.add.s()), app=self.app),
  550. Signature)
  551. def test_when_sig(self):
  552. s = self.add.s()
  553. assert maybe_signature(s, app=self.app) is s