Skip to content

Commit 412cecb

Browse files
committed
Obey all vs avail get modes
1 parent 8447a55 commit 412cecb

File tree

2 files changed

+54
-4
lines changed

2 files changed

+54
-4
lines changed

src/servicex_did_finder_lib/communication.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,14 @@ async def run_file_fetch_loop(did: str, servicex: ServiceXAdapter, info: Dict[st
6363
hold_till_end = did_info.file_count != -1
6464
acc = _accumulator(servicex, summary, hold_till_end)
6565

66-
async for file_info in user_callback(did_info.did, info):
67-
acc.add(file_info)
66+
try:
67+
async for file_info in user_callback(did_info.did, info):
68+
acc.add(file_info)
6869

69-
acc.send_on(did_info.file_count)
70+
acc.send_on(did_info.file_count)
71+
except Exception:
72+
if did_info.get_mode == 'all':
73+
raise
7074

7175
# Simple error checking and reporting
7276
if summary.file_count == 0:
@@ -84,7 +88,7 @@ async def run_file_fetch_loop(did: str, servicex: ServiceXAdapter, info: Dict[st
8488
}
8589
)
8690

87-
servicex.post_status_update(f'Completed load of file in {elapsed_time} seconds')
91+
servicex.post_status_update(f'Completed load of files in {elapsed_time} seconds')
8892

8993

9094
def rabbit_mq_callback(user_callback: UserDIDHandler, channel, method, properties, body,

tests/servicex_did_finder_lib/test_communication.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,52 @@ async def my_callback(did_name: str, info: Dict[str, Any]) \
175175
SXAdaptor.post_status_update.assert_any_call(ANY, severity='fatal')
176176

177177

178+
def test_failed_file_after_good(rabbitmq, SXAdaptor):
179+
'Test a callback that fails before any files are sent'
180+
181+
async def my_callback(did_name: str, info: Dict[str, Any]) \
182+
-> AsyncGenerator[Dict[str, Any], None]:
183+
yield {
184+
'paths': ["fork/it/over"],
185+
'adler32': 'no clue',
186+
'file_size': 22323,
187+
'file_events': 0,
188+
}
189+
raise Exception('that did not work')
190+
191+
init_rabbit_mq(my_callback, 'http://myrabbit.com', 'test_queue_name', retries=12,
192+
retry_interval=10)
193+
rabbitmq.send_did_request('hi-there')
194+
195+
# Make sure the file was sent along, along with the completion
196+
SXAdaptor.put_file_add.assert_called_once()
197+
SXAdaptor.put_fileset_complete.assert_not_called()
198+
SXAdaptor.post_status_update.assert_any_call(ANY, severity='fatal')
199+
200+
201+
def test_failed_file_after_good_with_avail(rabbitmq, SXAdaptor):
202+
'Test a callback that fails before any files are sent'
203+
204+
async def my_callback(did_name: str, info: Dict[str, Any]) \
205+
-> AsyncGenerator[Dict[str, Any], None]:
206+
yield {
207+
'paths': ["fork/it/over"],
208+
'adler32': 'no clue',
209+
'file_size': 22323,
210+
'file_events': 0,
211+
}
212+
raise Exception('that did not work')
213+
214+
init_rabbit_mq(my_callback, 'http://myrabbit.com', 'test_queue_name', retries=12,
215+
retry_interval=10)
216+
rabbitmq.send_did_request('hi-there?get=available')
217+
218+
# Make sure the file was sent along, along with the completion
219+
SXAdaptor.put_file_add.assert_called_once()
220+
SXAdaptor.put_fileset_complete.assert_called_once()
221+
SXAdaptor.post_status_update.assert_any_call("Completed load of files in 0 seconds")
222+
223+
178224
def test_no_files_returned(rabbitmq, SXAdaptor):
179225
'Test a callback that fails before any files are sent'
180226

0 commit comments

Comments
 (0)