MCPcopy
hub / github.com/SurgeDM/Surge / BenchmarkSingleDownloader

Function BenchmarkSingleDownloader

internal/engine/single/downloader_test.go:714–748  ·  view source on GitHub ↗

============================================================================= Benchmarks =============================================================================

(b *testing.B)

Source from the content-addressed store, hash-verified

712// =============================================================================
713
714func 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
750func TestSingleDownloader_Download_BootstrapSize(t *testing.T) {
751 tmpDir, cleanup, _ := testutil.TempDir("surge-bootstrap-single")

Callers

nothing calls this directly

Calls 10

CloseMethod · 0.95
DownloadMethod · 0.95
URLMethod · 0.95
TempDirFunction · 0.92
NewMockServerFunction · 0.92
WithFileSizeFunction · 0.92
WithRangeSupportFunction · 0.92
NewProgressStateFunction · 0.92
NewSingleDownloaderFunction · 0.85
CloseMethod · 0.45

Tested by

no test coverage detected