-
Notifications
You must be signed in to change notification settings - Fork 38
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
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
0142fc8
Reproduce infinite loop behaviour in unittest 'test_user_infinite_loo…
karanpanchal-crest 01e663d
Correct exception mesaage in unittest
karanpanchal-crest 268fbb3
change logger message
karanpanchal-crest 7e7b431
correct logger message
karanpanchal-crest 86cd3ca
add comment in streams.py and add 2sec window test case
karanpanchal-crest c05e8d4
add comment in streams.py and add 2sec window test case
karanpanchal-crest b05bd90
Change exception message
karanpanchal-crest 8715cc8
Correct comment message
karanpanchal-crest 210450f
resolved unitetst error
karanpanchal-crest bb939de
update behaviour for 1 second window size
RushiT0122 1eb074f
changelog and verison bump
kethan1122 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import unittest | ||
from unittest import mock | ||
import tap_zendesk | ||
from tap_zendesk.streams import Users | ||
from tap_zendesk.streams import STREAMS | ||
import singer | ||
import datetime | ||
from dateutil import tz | ||
|
||
|
||
class MockSearch: | ||
def __init__(self): | ||
self.count = 1001 | ||
self.updated_at = "test" | ||
|
||
def __iter__(self): | ||
return (self for x in range(4)) | ||
|
||
def search(self, test, updated_after, updated_before, type="user" ): | ||
# For window size less than 2 return less than or equal to 1000 records and for larger window return greater than 1000 records | ||
if (singer.strptime(updated_before) - singer.strptime(updated_after)).seconds < 2: | ||
self.count = 999 | ||
else: | ||
self.count = 1001 | ||
return self | ||
|
||
class TestUserSyncCheck(unittest.TestCase): | ||
@mock.patch('tap_zendesk.singer.utils.now', side_effect=lambda : datetime.datetime(2022, 4, 7, 1, 45, 21, 840535, tzinfo=tz.UTC)) | ||
def test_many_records_in_one_seconds_for_user(self, mocked_now): | ||
""" | ||
Reproduce infinite looping behavior for Users stream when user have many record in single seconds | ||
""" | ||
user_obj = Users(MockSearch(), {}) | ||
|
||
with self.assertRaises(Exception) as e: | ||
l = list(user_obj.sync({'bookmarks': {'users': {'updated_at': '2022-03-30T08:45:21.000000Z'}}})) | ||
|
||
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://develop.zendesk.com/hc/en-us/articles/360022563994--BREAKING-New-Search-API-Result-Limits') | ||
|
||
def test_many_records_in_one_seconds_for_user_with_3_sec_window(self): | ||
dbshah1212 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
""" | ||
To verify that if user give 3 seconds window then also we don't get infinite loop behavior | ||
""" | ||
user_obj = Users(client=MockSearch(), config={'search_window_size': 3}) | ||
|
||
with self.assertRaises(Exception) as e: | ||
l = list(user_obj.sync({'bookmarks': {'users': {'updated_at': '2022-03-30T08:45:21.000000Z'}}})) | ||
|
||
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://develop.zendesk.com/hc/en-us/articles/360022563994--BREAKING-New-Search-API-Result-Limits') | ||
|
||
def test_many_records_in_one_seconds_for_user_with_2_sec_window(self): | ||
""" | ||
To verify that if user give 2 seconds window then also we don't get infinite loop behavior | ||
""" | ||
user_obj = Users(client=MockSearch(), config={'search_window_size': 2}) | ||
|
||
with self.assertRaises(Exception) as e: | ||
l = list(user_obj.sync({'bookmarks': {'users': {'updated_at': '2022-03-30T08:45:21.000000Z'}}})) | ||
|
||
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://develop.zendesk.com/hc/en-us/articles/360022563994--BREAKING-New-Search-API-Result-Limits') | ||
|
||
def test_search_window_size_equals_1_sec(self): | ||
""" | ||
To verify that search window size 1 second cannot be configured | ||
""" | ||
|
||
with self.assertRaises(ValueError) as e: | ||
Users(client=MockSearch(), config={'search_window_size': 1}) | ||
|
||
self.assertEqual(str(e.exception), 'Search window size cannot be less than 2') |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)