MCPcopy
hub / github.com/rclone/rclone / testSyncWithMaxDuration

Function testSyncWithMaxDuration

fs/sync/sync_test.go:1493–1545  ·  view source on GitHub ↗

Test with a max transfer duration

(t *testing.T, cutoffMode fs.CutoffMode)

Source from the content-addressed store, hash-verified

1491
1492// Test with a max transfer duration
1493func testSyncWithMaxDuration(t *testing.T, cutoffMode fs.CutoffMode) {
1494 ctx := context.Background()
1495 ctx, ci := fs.AddConfig(ctx)
1496 if *fstest.RemoteName != "" {
1497 t.Skip("Skipping test on non local remote")
1498 }
1499 r := fstest.NewRun(t)
1500
1501 maxDuration := fs.Duration(250 * time.Millisecond)
1502 ci.MaxDuration = maxDuration
1503 ci.CutoffMode = cutoffMode
1504 ci.CheckFirst = true
1505 ci.OrderBy = "size"
1506 ci.Transfers = 1
1507 ci.Checkers = 1
1508 bytesPerSecond := 10 * 1024
1509 accounting.TokenBucket.SetBwLimit(fs.BwPair{Tx: fs.SizeSuffix(bytesPerSecond), Rx: fs.SizeSuffix(bytesPerSecond)})
1510 defer accounting.TokenBucket.SetBwLimit(fs.BwPair{Tx: -1, Rx: -1})
1511
1512 // write one small file which we expect to transfer and one big one which we don't
1513 file1 := r.WriteFile("file1", string(make([]byte, 16)), t1)
1514 file2 := r.WriteFile("file2", string(make([]byte, 50*1024)), t1)
1515 r.CheckLocalItems(t, file1, file2)
1516 r.CheckRemoteItems(t)
1517
1518 if runtime.GOOS == "darwin" {
1519 r.Flocal.Features().Disable("Copy") // macOS cloning is too fast for this test!
1520 if r.Fremote.Features().IsLocal {
1521 r.Fremote.Features().Disable("Copy") // macOS cloning is too fast for this test!
1522 }
1523 }
1524 accounting.GlobalStats().ResetCounters()
1525 // ctx = predictDstFromLogger(ctx) // not currently supported (but tests do pass for CutoffModeSoft)
1526 startTime := time.Now()
1527 err := Sync(ctx, r.Fremote, r.Flocal, false)
1528 // testLoggerVsLsf(ctx, r.Fremote, r.Flocal, operations.GetLoggerOpt(ctx).JSON, t)
1529 require.True(t, errors.Is(err, ErrorMaxDurationReached))
1530
1531 if cutoffMode == fs.CutoffModeHard {
1532 r.CheckRemoteItems(t, file1)
1533 assert.Equal(t, int64(1), accounting.GlobalStats().GetTransfers())
1534 } else {
1535 r.CheckRemoteItems(t, file1, file2)
1536 assert.Equal(t, int64(2), accounting.GlobalStats().GetTransfers())
1537 }
1538
1539 elapsed := time.Since(startTime)
1540 const maxTransferTime = 20 * time.Second
1541
1542 what := fmt.Sprintf("expecting elapsed time %v between %v and %v", elapsed, maxDuration, maxTransferTime)
1543 assert.True(t, elapsed >= time.Duration(maxDuration), what)
1544 assert.True(t, elapsed < maxTransferTime, what)
1545}
1546
1547func TestSyncWithMaxDuration(t *testing.T) {
1548 t.Run("Hard", func(t *testing.T) {

Callers 1

TestSyncWithMaxDurationFunction · 0.85

Calls 15

WriteFileMethod · 0.95
CheckLocalItemsMethod · 0.95
CheckRemoteItemsMethod · 0.95
AddConfigFunction · 0.92
NewRunFunction · 0.92
DurationTypeAlias · 0.92
SizeSuffixTypeAlias · 0.92
GlobalStatsFunction · 0.92
SyncFunction · 0.85
SetBwLimitMethod · 0.80
DisableMethod · 0.80
ResetCountersMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…