-
Notifications
You must be signed in to change notification settings - Fork 52
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 25859/handle s3 files race condition #67
Open
rdeshmukh15
wants to merge
15
commits into
master
Choose a base branch
from
TDL-25859/handle-s3-files-race-condition
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
7d03dbf
changes to handle s3 files modified date race condition
rdeshmukh15 bf476e1
date format change
rdeshmukh15 3dbe382
date format change while writing bookmark
rdeshmukh15 2126092
removes will download logger and adds logger to log s3_files data
fcd39c1
stores results of sorted first and then loops over it
ca9f713
changes in logger and logging len of sorted_files
fc1255f
adds code to sort using heapq
6484a80
sorts properly
ed9cc0f
Reeduce chunk_size to 1000 to get rid of -9
c770fbd
date windowing for 7 days in sync.py
3acbcb1
using itertools to group the data in 7 days date window
34da79d
handles race condition
fd7019f
adds unit test for the changes
b7b30cc
reafctoring
005108b
refactors the test function names and adds docstrings
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,68 @@ | ||
import unittest | ||
from unittest.mock import patch, MagicMock | ||
from datetime import datetime | ||
from tap_s3_csv import sync_stream | ||
|
||
class TestSyncStream(unittest.TestCase): | ||
|
||
@patch('tap_s3_csv.s3.get_input_files_for_table') | ||
@patch('tap_s3_csv.sync.sync_table_file') | ||
@patch('tap_s3_csv.singer.get_bookmark') | ||
@patch('tap_s3_csv.singer.write_bookmark') | ||
@patch('tap_s3_csv.singer.write_state') | ||
@patch('tap_s3_csv.LOGGER') | ||
def test_sync_stream_with_files_older_than_sync_start_time(self, mock_logger, mock_write_state, mock_write_bookmark, mock_get_bookmark, mock_sync_table_file, mock_get_input_files_for_table): | ||
""" | ||
Tests the sync_stream function when the last_modified date of files is earlier than sync_start_time. | ||
In this case, the bookmark is updated to the last_modified date of the file. | ||
""" | ||
mock_get_bookmark.return_value = '2024-01-01T00:00:00Z' | ||
mock_get_input_files_for_table.return_value = [ | ||
{'key': 'file1.csv', 'last_modified': datetime(2024, 8, 13, 12, 0, 0)} | ||
] | ||
mock_sync_table_file.return_value = 1 | ||
mock_write_bookmark.return_value = '2024-08-13T12:00:00Z' | ||
|
||
config = {'start_date': '2024-01-01T00:00:00Z'} | ||
state = {} | ||
table_spec = {'table_name': 'test_table'} | ||
stream = None | ||
sync_start_time = datetime(2024, 8, 14, 12, 0, 0) | ||
|
||
records_streamed = sync_stream(config, state, table_spec, stream, sync_start_time) | ||
|
||
self.assertEqual(records_streamed, 1) | ||
# Verify that the bookmark was updated to the last_modified date of the file | ||
mock_write_bookmark.assert_called_with(state, 'test_table', 'modified_since', '2024-08-13T12:00:00') | ||
mock_write_state.assert_called_once() | ||
|
||
@patch('tap_s3_csv.s3.get_input_files_for_table') | ||
@patch('tap_s3_csv.sync.sync_table_file') | ||
@patch('tap_s3_csv.singer.get_bookmark') | ||
@patch('tap_s3_csv.singer.write_bookmark') | ||
@patch('tap_s3_csv.singer.write_state') | ||
@patch('tap_s3_csv.LOGGER') | ||
def test_sync_stream_with_files_newer_than_sync_start_time(self, mock_logger, mock_write_state, mock_write_bookmark, mock_get_bookmark, mock_sync_table_file, mock_get_input_files_for_table): | ||
""" | ||
Tests the sync_stream function when the last_modified date of files is later than sync_start_time. | ||
In this case, the bookmark is updated to sync_start_time. | ||
""" | ||
mock_get_bookmark.return_value = '2024-01-01T00:00:00Z' | ||
mock_get_input_files_for_table.return_value = [ | ||
{'key': 'file1.csv', 'last_modified': datetime(2024, 8, 15, 12, 0, 0)} | ||
] | ||
mock_sync_table_file.return_value = 1 | ||
mock_write_bookmark.return_value = '2024-08-15T12:00:00Z' | ||
|
||
config = {'start_date': '2024-01-01T00:00:00Z'} | ||
state = {} | ||
table_spec = {'table_name': 'test_table'} | ||
stream = None | ||
sync_start_time = datetime(2024, 8, 14, 12, 0, 0) | ||
|
||
records_streamed = sync_stream(config, state, table_spec, stream, sync_start_time) | ||
|
||
self.assertEqual(records_streamed, 1) | ||
# Verify that the bookmark was updated to the sync_start_time | ||
mock_write_bookmark.assert_called_with(state, 'test_table', 'modified_since', sync_start_time.isoformat()) | ||
mock_write_state.assert_called_once() |
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.
Please add unit test for this change.