Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TDL-6756: Fix Infinite Loop for Users #103

Merged
merged 11 commits into from
May 25, 2023

Conversation

karanpanchal-crest
Copy link
Contributor

Description of change

  • Reproduce infinite loop behavior in unit test 'test_user_infinite_loop.py' and correct that behavior

Manual QA steps

  • Infinite behavior not happened if single second has more than 1000 records.

Risks

Rollback steps

  • revert this branch

users = self.client.search("", updated_after=parsed_start, updated_before=parsed_end, type="user")

# NB: Zendesk will return an error on the 1001st record, so we
# need to check total response size before iterating
# See: https://develop.zendesk.com/hc/en-us/articles/360022563994--BREAKING-New-Search-API-Result-Limits
if users.count > 1000:
if search_window_size > 1:
# to avoid infinite loop behavior we should reduce the window if it is greater than 2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# to avoid infinite loop behavior we should reduce the window if it is greater than 2
# To avoid infinite loop behavior we should reduce the window if it is greater than 2

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added suggested changes

@@ -244,20 +244,21 @@ def sync(self, state):
while start < sync_end:
parsed_start = singer.strftime(start, "%Y-%m-%dT%H:%M:%SZ")
parsed_end = min(singer.strftime(end, "%Y-%m-%dT%H:%M:%SZ"), parsed_sync_end)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to have, elaborate why we need to take min of 2 timestamps.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tap is using window so if 'end' is minimum than window size then consider it otherwise it will use normal 'end' (start + date window)


class TestUserSyncCheck(unittest.TestCase):

def test_many_records_in_one_seconds_for_user(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On local env, this unit test is failing,

$ nosetests test/unittests/test_user_infinite_loop.py:TestUserSyncCheck.test_many_records_in_one_seconds_for_user
.
.
======================================================================
FAIL: Reproduce infinite looping behavior for Users stream when user have many record in single seconds
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/opt/code/tap-zendesk/test/unittests/test_user_infinite_loop.py", line 36, in test_many_records_in_one_seconds_for_user
    self.assertEqual(str(e.exception), 'users - Unable to get all users within minimum window of a single second (2022-03-30T08:45:21Z), found 1001 users within this timestamp. Zendesk can only provide a maximum of 1000 users per request. See: https://de/
velop.zendesk.com/hc/en-us/articles/360022563994--BREAKING-New-Search-API-Result-Limits')
AssertionError: 'user[71 chars]022-04-14T08:45:20Z), found 1001 users within [176 chars]mits' != 'user[71 chars]022-03-30T08:45:21Z), found 1001 users within [176 chars]mits'
Diff is 801 characters long. Set self.maxDiff to None to see it.
-------------------- >> begin captured stdout << ---------------------
{"type": "STATE", "value": {"bookmarks": {"users": {"updated_at": "2022-04-14T08:45:20Z"}}}}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We expect static datetime in the exception message, but the unit test is internally using the current datetime. So, we mocked now() with static datetime

@RushiT0122 RushiT0122 self-requested a review September 14, 2022 17:18
@RushiT0122 RushiT0122 force-pushed the TDL-6756-Fix-Infinite-Loop-for-Users branch from bb081e1 to bb939de Compare May 23, 2023 10:29
@Rohan397 Rohan397 merged commit 78872f1 into master May 25, 2023
Karthipillai pushed a commit to MarletteFunding/singer-tap-zendesk that referenced this pull request Oct 2, 2023
* Reproduce infinite loop behaviour in unittest 'test_user_infinite_loop.py' and correct that behaviour

* Correct exception mesaage in unittest

* change logger message

* correct logger message

* add comment in streams.py and add 2sec window test case

* add comment in streams.py and add 2sec window test case

* Change exception message

* Correct comment message

* resolved unitetst error

* update behaviour for 1 second window size

* changelog and verison bump

---------

Co-authored-by: Rushikesh Todkar <98420315+RushiT0122@users.noreply.github.com>
Co-authored-by: kethan1122 <kcherukuri@talend.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants