MCPcopy
hub / github.com/kopia/kopia / TestParallelUploadOfLargeFiles

Function TestParallelUploadOfLargeFiles

snapshot/upload/upload_test.go:1307–1401  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1305}
1306
1307func TestParallelUploadOfLargeFiles(t *testing.T) {
1308 t.Parallel()
1309
1310 ctx := testlogging.Context(t)
1311 th := newUploadTestHarness(ctx, t)
1312
1313 t.Cleanup(th.cleanup)
1314
1315 u := NewUploader(th.repo)
1316 u.ParallelUploads = 10
1317
1318 pol := *policy.DefaultPolicy
1319
1320 // change policies so that all files above this size are uploaded in parallel
1321 // use an unusual number so that it's easy to spot.
1322 const chunkSize = 10203040
1323
1324 // future reader, the chunk size must be greater than 4 MiB to make sure splitters are
1325 // not used in degenerate form.
1326 require.Greater(t, chunkSize, 4<<20)
1327
1328 n := policy.OptionalInt64(chunkSize)
1329 pol.UploadPolicy.ParallelUploadAboveSize = &n
1330
1331 policyTree := policy.BuildTree(nil, &pol)
1332
1333 testutil.SkipTestOnCIUnlessLinuxAMD64(t)
1334 td := testutil.TempDirectory(t)
1335
1336 // Write 2 x 50MB files
1337 var files []*os.File
1338
1339 for i := range 2 {
1340 f, cerr := os.Create(filepath.Join(td, fmt.Sprintf("file-%v", i)))
1341 require.NoError(t, cerr)
1342
1343 files = append(files, f)
1344 }
1345
1346 for range 1000 {
1347 buf := make([]byte, 50000)
1348
1349 for _, f := range files {
1350 rand.Read(buf)
1351
1352 _, werr := f.Write(buf)
1353 require.NoError(t, werr)
1354 }
1355 }
1356
1357 for _, f := range files {
1358 f.Close()
1359 }
1360
1361 srcdir, err := localfs.Directory(td)
1362 require.NoError(t, err)
1363
1364 man, err := u.Upload(ctx, srcdir, policyTree, snapshot.SourceInfo{})

Callers

nothing calls this directly

Calls 15

UploadMethod · 0.95
ContextFunction · 0.92
OptionalInt64TypeAlias · 0.92
BuildTreeFunction · 0.92
TempDirectoryFunction · 0.92
DirectoryFunction · 0.92
EnsureTypeFunction · 0.92
EntryFromDirEntryFunction · 0.92
IterateEntriesFunction · 0.92
ParseIDFunction · 0.92
LoadIndexObjectFunction · 0.92

Tested by

no test coverage detected