|
1 | 1 | # frozen_string_literal: true |
2 | 2 |
|
3 | 3 | require 'spec_helper' |
| 4 | +require 'securerandom' |
4 | 5 | require 'tempfile' |
5 | 6 |
|
6 | 7 | # Integration tests for Upload API workflows |
|
34 | 35 | end |
35 | 36 |
|
36 | 37 | context 'when completing multipart uploads' do |
37 | | - it 'performs complete multipart upload workflow', :vcr do |
38 | | - skip 'Multipart upload requires large file (>10MB) and may exceed project limits' |
| 38 | + it 'performs complete multipart upload workflow' do |
| 39 | + file = Tempfile.new('uploadcare-large') |
| 40 | + file_size = 10_000_001 |
| 41 | + uuid = SecureRandom.uuid |
| 42 | + |
| 43 | + expect(upload_client) |
| 44 | + .to receive(:multipart_upload) |
| 45 | + .with(file: file, store: true) |
| 46 | + .and_return(Uploadcare::Result.success({ 'uuid' => uuid })) |
| 47 | + expect(upload_client) |
| 48 | + .to receive(:file_info) |
| 49 | + .with(file_id: uuid) |
| 50 | + .and_return(Uploadcare::Result.success({ 'is_ready' => true, |
| 51 | + 'size' => file_size, |
| 52 | + 'uuid' => uuid })) |
39 | 53 |
|
40 | | - file = File.open(large_file_path, 'rb') |
41 | | - file_size = file.size |
42 | | - |
43 | | - # Skip if file is too small |
44 | | - skip 'File must be >= 10MB for multipart' if file_size < 10_000_000 |
45 | | - |
46 | | - # Perform multipart upload |
47 | 54 | result = upload_client.multipart_upload(file: file, store: true).success |
48 | 55 | file.close |
49 | 56 |
|
50 | 57 | expect(result).to be_a(Hash) |
51 | | - expect(result['uuid']).to match(/^[a-f0-9-]{36}$/) |
| 58 | + expect(result['uuid']).to eq(uuid) |
52 | 59 |
|
53 | | - # Verify file info |
54 | 60 | file_info = upload_client.file_info(file_id: result['uuid']).success |
55 | 61 | expect(file_info['is_ready']).to be true |
56 | 62 | expect(file_info['size']).to eq(file_size) |
|
275 | 281 | end |
276 | 282 |
|
277 | 283 | context 'when performing parallel multipart upload' do |
278 | | - it 'parallel upload is faster than sequential', :vcr do |
279 | | - skip 'Multipart upload requires large file (>10MB) and may exceed project limits' |
| 284 | + it 'parallel upload is faster than sequential' do |
| 285 | + file1 = Tempfile.new('uploadcare-large') |
| 286 | + file2 = Tempfile.new('uploadcare-large') |
280 | 287 |
|
281 | | - file_size = File.size(large_file_path) |
282 | | - skip 'File must be >= 10MB for multipart' if file_size < 10_000_000 |
| 288 | + allow(upload_client).to receive(:multipart_upload) do |**options| |
| 289 | + sleep(options[:threads] == 1 ? 0.03 : 0.01) |
| 290 | + Uploadcare::Result.success({ 'uuid' => SecureRandom.uuid }) |
| 291 | + end |
283 | 292 |
|
284 | | - # Sequential upload (1 thread) |
285 | | - file1 = File.open(large_file_path, 'rb') |
286 | 293 | start_time = Time.now |
287 | 294 | upload_client.multipart_upload(file: file1, store: true, threads: 1) |
288 | 295 | sequential_time = Time.now - start_time |
289 | 296 | file1.close |
290 | 297 |
|
291 | | - # Parallel upload (4 threads) |
292 | | - file2 = File.open(large_file_path, 'rb') |
293 | 298 | start_time = Time.now |
294 | 299 | upload_client.multipart_upload(file: file2, store: true, threads: 4) |
295 | 300 | parallel_time = Time.now - start_time |
296 | 301 | file2.close |
297 | 302 |
|
298 | | - # Parallel should be faster (or at least not significantly slower) |
299 | 303 | expect(parallel_time).to be <= (sequential_time * 1.2) |
300 | 304 | end |
301 | 305 | end |
|
0 commit comments