| |
@@ -0,0 +1,31 @@
|
| |
+ import mock
|
| |
+ import unittest
|
| |
+ import koji
|
| |
+
|
| |
+
|
| |
+ class TestItercall(unittest.TestCase):
|
| |
+
|
| |
+ def test_itercall(self):
|
| |
+
|
| |
+ ks = koji.ClientSession('http://dumy.hub/address')
|
| |
+ ks.multiCall = mock.Mock(return_value=[['ret1'], ['ret2'], ['ret3']])
|
| |
+
|
| |
+ args = ['arg1', 'arg2', 'arg3']
|
| |
+ rets = list(ks.itercall(args, lambda arg: ks.foo(arg)))
|
| |
+
|
| |
+ ks.multiCall.assert_called_once_with()
|
| |
+ self.assertEquals(['ret1', 'ret2', 'ret3'], rets)
|
| |
+
|
| |
+
|
| |
+ def test_itercall_chunk_size(self):
|
| |
+
|
| |
+ ks = koji.ClientSession('http://dumy.hub/address',
|
| |
+ opts={'itercall_chunk_size': 2})
|
| |
+ mock_rets = [[[1], [2]], [[3], [4]], [[5], [6]], [[7]]]
|
| |
+ ks.multiCall = mock.Mock(side_effect=lambda: mock_rets.pop(0))
|
| |
+
|
| |
+ args = [111, 222, 333, 444, 555, 666, 777]
|
| |
+ rets = list(ks.itercall(args, lambda arg: ks.foo(arg)))
|
| |
+
|
| |
+ ks.multiCall.assert_has_calls([mock.call()] * 4)
|
| |
+ self.assertEquals(range(1,8), rets)
|
| |
itercall is an alternative way of using Koji multiCall API from
ClientSession in Python.
multiCall is a feature of Koji XML-RPC which allows multiple RPC calls
to be grouped into a single XML-RPC call and processed in batch by
Koji hub.
Typical usage of multicall from Python:
With itercall this can be simplified to:
Pros
Itercall makes coding multiCall easier. With itercall developers are
more likely to use multicall in their code, which should benefit both
their applications and Koji.
Itercall splits big multicalls into smaller chunks (configurable),
which prevents timeouts, conserves both client and hub memory (the
whole request and reply don't need to be buffered).
Itercall can save a lot of hub work in case client wants to exit early
without processing all results, or if fault occurs.
Moreover, nested itercall loops are easily doable, which is not
straightforward with standard multicall API.