106106 expect ( result . error ) . to be_a ( ArgumentError )
107107 expect ( result . error . message ) . to eq ( 'part_size must be > 0' )
108108 end
109+
110+ it 'returns a failure Result when threads exceeds config.upload_threads' do
111+ result = uploader . upload ( file : tempfile , threads : 3 )
112+
113+ expect ( result . failure? ) . to be ( true )
114+ expect ( result . error ) . to be_a ( ArgumentError )
115+ expect ( result . error . message ) . to eq ( 'threads must be <= 2' )
116+ end
109117 end
110118
111119 context 'when performing sequential upload (threads <= 1)' do
271279 end
272280
273281 it 'uploads correct data chunks in parallel' do
282+ high_thread_config = Uploadcare ::Configuration . new (
283+ public_key : 'demopublickey' ,
284+ secret_key : 'demosecretkey' ,
285+ auth_type : 'Uploadcare.Simple' ,
286+ multipart_chunk_size : 1024 ,
287+ upload_threads : 3
288+ )
289+ high_thread_uploader = described_class . new ( upload_client : upload_client , config : high_thread_config )
274290 chunks = Mutex . new
275291 all_chunks = { }
276292 allow ( upload_client ) . to receive ( :upload_part_to_url ) do |url , data |
277293 chunks . synchronize { all_chunks [ url ] = data . bytesize }
278294 end
279295
280- uploader . upload ( file : tempfile , threads : 3 )
296+ high_thread_uploader . upload ( file : tempfile , threads : 3 )
281297 expect ( all_chunks . values ) . to all ( eq ( 1024 ) )
282298 expect ( all_chunks . size ) . to eq ( 3 )
283299 end
300316 expect ( final_uploaded ) . to eq ( 3072 )
301317 end
302318
303- it 'works with more threads than parts' do
304- result = uploader . upload ( file : tempfile , threads : 10 )
319+ it 'works with more threads than parts when allowed by config' do
320+ high_thread_config = Uploadcare ::Configuration . new (
321+ public_key : 'demopublickey' ,
322+ secret_key : 'demosecretkey' ,
323+ auth_type : 'Uploadcare.Simple' ,
324+ multipart_chunk_size : 1024 ,
325+ upload_threads : 10
326+ )
327+ high_thread_uploader = described_class . new ( upload_client : upload_client , config : high_thread_config )
328+
329+ result = high_thread_uploader . upload ( file : tempfile , threads : 10 )
305330 expect ( result . success? ) . to be ( true )
306331 end
307332
329354 end
330355
331356 it 'propagates the first error from parallel workers' do
357+ high_thread_config = Uploadcare ::Configuration . new (
358+ public_key : 'demopublickey' ,
359+ secret_key : 'demosecretkey' ,
360+ auth_type : 'Uploadcare.Simple' ,
361+ multipart_chunk_size : 1024 ,
362+ upload_threads : 3
363+ )
364+ high_thread_uploader = described_class . new ( upload_client : upload_client , config : high_thread_config )
332365 allow ( upload_client ) . to receive ( :upload_part_to_url ) do
333366 raise 'network timeout'
334367 end
335368
336- result = uploader . upload ( file : tempfile , threads : 3 )
369+ result = high_thread_uploader . upload ( file : tempfile , threads : 3 )
337370 expect ( result . failure? ) . to be ( true )
338371 expect ( result . error ) . to be_a ( RuntimeError )
339372 end
@@ -494,6 +527,14 @@ def seek(_pos) = nil
494527
495528 context 'when performing parallel upload with offset >= total_size' do
496529 it 'handles more presigned URLs than needed' do
530+ high_thread_config = Uploadcare ::Configuration . new (
531+ public_key : 'demopublickey' ,
532+ secret_key : 'demosecretkey' ,
533+ auth_type : 'Uploadcare.Simple' ,
534+ multipart_chunk_size : 1024 ,
535+ upload_threads : 3
536+ )
537+ high_thread_uploader = described_class . new ( upload_client : upload_client , config : high_thread_config )
497538 small_content = 'C' * 1024
498539 small_file = Tempfile . new ( [ 'small_parallel' , '.bin' ] )
499540 small_file . binmode
@@ -511,7 +552,7 @@ def seek(_pos) = nil
511552 uploaded_urls << url
512553 end
513554
514- result = uploader . upload ( file : small_file , threads : 3 )
555+ result = high_thread_uploader . upload ( file : small_file , threads : 3 )
515556 expect ( result . success? ) . to be ( true )
516557 expect ( uploaded_urls . length ) . to eq ( 1 )
517558
0 commit comments