def test_arguments_are_preserved_in_retries(self):
        for i in xrange(3):
            doc = search.Document(doc_id=i % 'doc%d', fields=[
                search.TextField('prop', 'val'),
                search.NumberField('index', i)
            ])
            search.Index('my_index').put(doc)

        exception = search.TransientError('oops')
        failing_index_search = test_utils.FailingFunction(
            search.Index.search, exception, 3)

        search_counter = test_utils.CallCounter(gae_search_services.search)

        gae_search_ctx = self.swap(
            search.Index, 'search', failing_index_search)
        search_counter_ctx = self.swap(
            gae_search_services, 'search', search_counter)
        with gae_search_ctx, search_counter_ctx:
            result, cursor = gae_search_services.search(
                'prop:val',
                'my_index',
                sort='-index',
                limit=2,
                ids_only=True,
                retries=4)

        failing_index_search2 = test_utils.FailingFunction(
            search.Index.search,
            exception,
            3)

        search_counter2 = test_utils.CallCounter(gae_search_services.search)

        gae_search_ctx2 = self.swap(
            search.Index, 'search', failing_index_search2)
        search_counter_ctx2 = self.swap(
            gae_search_services, 'search', search_counter2)
        with gae_search_ctx2, search_counter_ctx2:
            result2, cursor = gae_search_services.search(
                'prop:val',
                'my_index',
                sort='-index',
                limit=2,
                cursor=cursor,
                ids_only=True,
                retries=4)

        self.assertEqual(search_counter.times_called, 4)
        self.assertEqual(result, ['doc2', 'doc1'])

        # also check that the cursor is preserved
        self.assertEqual(search_counter2.times_called, 4)
        self.assertEqual(result2, ['doc0'])
dataset/ETHPy150Open oppia/oppia/core/platform/search/gae_search_services_test.py/SearchQueryTests.test_arguments_are_preserved_in_retries/swapped operands of `%`