fetch_ml/tests/benchmarks/go_native_leak_test.go
Jeremie Fraeys 38c09c92bb
test(benchmarks): fix native lib benchmarks when disabled
- Add skip checks to native queue benchmarks when FETCHML_NATIVE_LIBS=0
- Skip TestGoNativeArtifactScanLeak cleanly instead of 100 warnings
- Add build tags (!native_libs/native_libs) for Go vs Native comparison
- Add benchmark-native and benchmark-compare Makefile targets
2026-02-18 12:45:30 -05:00

69 lines
1.6 KiB
Go

package benchmarks
import (
"os"
"testing"
"github.com/jfraeys/fetch_ml/internal/worker"
)
// TestGoNativeLeakStress runs 1000 iterations through Go->C++ integration
func TestGoNativeLeakStress(t *testing.T) {
tmpDir := t.TempDir()
// Create multiple test files
for i := 0; i < 10; i++ {
content := make([]byte, 1024*1024) // 1MB each
for j := range content {
content[j] = byte(i * j)
}
if err := os.WriteFile(tmpDir+"/test_"+string(rune('a'+i))+".dat", content, 0644); err != nil {
t.Fatal(err)
}
}
// Run 1000 hash operations through Go wrapper
for i := 0; i < 1000; i++ {
hash, err := worker.DirOverallSHA256Hex(tmpDir)
if err != nil {
t.Fatalf("Hash %d failed: %v", i, err)
}
if len(hash) != 64 {
t.Fatalf("Hash %d: expected 64 chars, got %d", i, len(hash))
}
if i%100 == 0 {
t.Logf("Completed %d iterations", i)
}
}
t.Logf("Completed 1000 iterations through Go->C++ integration")
}
// TestGoNativeArtifactScanLeak tests artifact scanner through Go
func TestGoNativeArtifactScanLeak(t *testing.T) {
if !worker.HasSIMDSHA256() {
t.Skip("Native libraries not available (build with -tags native_libs)")
}
tmpDir := t.TempDir()
// Create test files
for i := 0; i < 50; i++ {
if err := os.WriteFile(tmpDir+"/file_"+string(rune('a'+i%26))+".txt", []byte("data"), 0644); err != nil {
t.Fatal(err)
}
}
// Run 100 scans
for i := 0; i < 100; i++ {
_, err := worker.ScanArtifactsNative(tmpDir)
if err != nil {
t.Logf("Scan %d: %v (may be expected if native disabled)", i, err)
}
if i%25 == 0 {
t.Logf("Completed %d scans", i)
}
}
}