============================================================================= Benchmarks =============================================================================
(b *testing.B)
| 712 | // ============================================================================= |
| 713 | |
| 714 | func BenchmarkSingleDownloader(b *testing.B) { |
| 715 | tmpDir, cleanup, _ := testutil.TempDir("surge-bench-single") |
| 716 | defer cleanup() |
| 717 | |
| 718 | fileSize := int64(10 * types.MB) |
| 719 | server := testutil.NewMockServer( |
| 720 | testutil.WithFileSize(fileSize), |
| 721 | testutil.WithRangeSupport(false), |
| 722 | ) |
| 723 | defer server.Close() |
| 724 | |
| 725 | destPath := filepath.Join(tmpDir, "bench_single.bin") |
| 726 | state := types.NewProgressState("bench-single", fileSize) |
| 727 | runtime := &types.RuntimeConfig{} |
| 728 | |
| 729 | downloader := NewSingleDownloader("bench-id", nil, state, runtime) |
| 730 | |
| 731 | b.ResetTimer() |
| 732 | b.ReportAllocs() |
| 733 | |
| 734 | for i := 0; i < b.N; i++ { |
| 735 | ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) |
| 736 | // Pre-create incomplete file (simulating processing layer) |
| 737 | if f, err := os.Create(destPath + ".surge"); err == nil { |
| 738 | _ = f.Close() |
| 739 | } |
| 740 | |
| 741 | err := downloader.Download(ctx, server.URL(), destPath, fileSize, "bench.bin") |
| 742 | if err != nil { |
| 743 | b.Fatalf("Download failed: %v", err) |
| 744 | } |
| 745 | cancel() |
| 746 | _ = os.Remove(destPath) |
| 747 | } |
| 748 | } |
| 749 | |
| 750 | func TestSingleDownloader_Download_BootstrapSize(t *testing.T) { |
| 751 | tmpDir, cleanup, _ := testutil.TempDir("surge-bootstrap-single") |
nothing calls this directly
no test coverage detected