Some checks failed
Documentation / build-and-publish (push) Waiting to run
Test / test (push) Waiting to run
Checkout test / test (push) Successful in 5s
CI with Native Libraries / test-native (push) Has been cancelled
CI with Native Libraries / build-release (push) Has been cancelled
65 lines
1.5 KiB
Go
65 lines
1.5 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) {
|
|
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)
|
|
}
|
|
}
|
|
}
|