MCPcopy
hub / github.com/rclone/rclone / TestMaxTransfer

Function TestMaxTransfer

fs/sync/sync_test.go:2692–2739  ·  view source on GitHub ↗

Test that aborting on --max-transfer works

(t *testing.T)

Source from the content-addressed store, hash-verified

2690
2691// Test that aborting on --max-transfer works
2692func TestMaxTransfer(t *testing.T) {
2693 ctx := context.Background()
2694 ctx, ci := fs.AddConfig(ctx)
2695 ci.MaxTransfer = 3 * 1024
2696 ci.Transfers = 1
2697 ci.Checkers = 1
2698 ci.CutoffMode = fs.CutoffModeHard
2699
2700 test := func(t *testing.T, cutoff fs.CutoffMode) {
2701 r := fstest.NewRun(t)
2702 ci.CutoffMode = cutoff
2703
2704 if r.Fremote.Name() != "local" {
2705 t.Skip("This test only runs on local")
2706 }
2707
2708 // Create file on source
2709 file1 := r.WriteFile("file1", string(make([]byte, 5*1024)), t1)
2710 file2 := r.WriteFile("file2", string(make([]byte, 2*1024)), t1)
2711 file3 := r.WriteFile("file3", string(make([]byte, 3*1024)), t1)
2712 r.CheckLocalItems(t, file1, file2, file3)
2713 r.CheckRemoteItems(t)
2714
2715 if runtime.GOOS == "darwin" {
2716 // disable server-side copies as they don't count towards transfer size stats
2717 r.Flocal.Features().Disable("Copy")
2718 if r.Fremote.Features().IsLocal {
2719 r.Fremote.Features().Disable("Copy")
2720 }
2721 }
2722
2723 accounting.GlobalStats().ResetCounters()
2724
2725 // ctx = predictDstFromLogger(ctx) // not currently supported
2726 err := Sync(ctx, r.Fremote, r.Flocal, false)
2727 // testLoggerVsLsf(ctx, r.Fremote, r.Flocal, operations.GetLoggerOpt(ctx).JSON, t)
2728 expectedErr := fserrors.FsError(accounting.ErrorMaxTransferLimitReachedFatal)
2729 if cutoff != fs.CutoffModeHard {
2730 expectedErr = accounting.ErrorMaxTransferLimitReachedGraceful
2731 }
2732 fserrors.Count(expectedErr)
2733 assert.Equal(t, expectedErr, err)
2734 }
2735
2736 t.Run("Hard", func(t *testing.T) { test(t, fs.CutoffModeHard) })
2737 t.Run("Soft", func(t *testing.T) { test(t, fs.CutoffModeSoft) })
2738 t.Run("Cautious", func(t *testing.T) { test(t, fs.CutoffModeCautious) })
2739}
2740
2741func testSyncConcurrent(t *testing.T, subtest string) {
2742 const (

Callers

nothing calls this directly

Calls 15

WriteFileMethod · 0.95
CheckLocalItemsMethod · 0.95
CheckRemoteItemsMethod · 0.95
AddConfigFunction · 0.92
NewRunFunction · 0.92
GlobalStatsFunction · 0.92
FsErrorFunction · 0.92
CountFunction · 0.92
SyncFunction · 0.85
DisableMethod · 0.80
ResetCountersMethod · 0.80
NameMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…