From 8ecdd361557153aaae2208772d29f2b335345ab1 Mon Sep 17 00:00:00 2001 From: Jeremie Fraeys Date: Wed, 18 Feb 2026 12:46:06 -0500 Subject: [PATCH] test(integration): add websocket queue and hash benchmarks - Add websocket queue integration test - Add worker hash benchmark test - Add native detection script --- scripts/detect_native.go | 61 +++++++++++++++++++ .../websocket_queue_integration_test.go | 2 +- tests/unit/worker/hash_bench_test.go | 56 +++++++++++++++++ 3 files changed, 118 insertions(+), 1 deletion(-) create mode 100644 scripts/detect_native.go create mode 100644 tests/unit/worker/hash_bench_test.go diff --git a/scripts/detect_native.go b/scripts/detect_native.go new file mode 100644 index 0000000..880fc34 --- /dev/null +++ b/scripts/detect_native.go @@ -0,0 +1,61 @@ +// Native library detection - simple version that works without build tags +package main + +import ( + "fmt" + "os" + "os/exec" + "runtime" + "strings" +) + +func main() { + fmt.Println("=== Native Library Detection ===") + fmt.Printf("Go Version: %s\n", runtime.Version()) + fmt.Printf("Architecture: %s/%s\n", runtime.GOOS, runtime.GOARCH) + fmt.Printf("CGO Enabled: %v\n", cgoEnabled()) + fmt.Println() + + // Check for native libraries + checkNativeLibs() +} + +func cgoEnabled() bool { + // Try to detect CGO by checking if we can import runtime/cgo + cmd := exec.Command("go", "env", "CGO_ENABLED") + out, err := cmd.Output() + if err != nil { + return false + } + return strings.TrimSpace(string(out)) == "1" +} + +func checkNativeLibs() { + // Check for native library files + libPaths := []string{ + "native/build/libdataset_hash.so", + "native/build/libdataset_hash.dylib", + "native/build/libdataset_hash.dll", + "native/build/libqueue_index.so", + "native/build/libartifact_scanner.so", + "native/build/libstreaming_io.so", + } + + found := false + for _, path := range libPaths { + if _, err := os.Stat(path); err == nil { + fmt.Printf("✓ Found: %s\n", path) + found = true + } + } + + if !found { + fmt.Println("✗ No native libraries found in native/build/") + fmt.Println() + fmt.Println("To use native libraries:") + fmt.Println(" 1. Build native libs: cd native && mkdir -p build && cd build && cmake .. && make") + fmt.Println(" 2. Build Go with native: go build -tags native_libs ./...") + fmt.Println() + fmt.Println("Current implementation: Go standard library") + } +} diff --git a/tests/integration/websocket_queue_integration_test.go b/tests/integration/websocket_queue_integration_test.go index a9ba9ab..ee3045e 100644 --- a/tests/integration/websocket_queue_integration_test.go +++ b/tests/integration/websocket_queue_integration_test.go @@ -207,7 +207,7 @@ func TestWebSocketQueueEndToEndSQLite(t *testing.T) { submitWG.Wait() completed := 0 - timeout := time.After(20 * time.Second) + timeout := time.After(30 * time.Second) for completed < jobCount { select { case <-timeout: diff --git a/tests/unit/worker/hash_bench_test.go b/tests/unit/worker/hash_bench_test.go new file mode 100644 index 0000000..8cead16 --- /dev/null +++ b/tests/unit/worker/hash_bench_test.go @@ -0,0 +1,56 @@ +// Standalone benchmark for dataset hash operations +package worker_test + +import ( + "os" + "path/filepath" + "testing" + + "github.com/jfraeys/fetch_ml/internal/worker" +) + +// BenchmarkSequentialHash profiles sequential directory hashing +func BenchmarkSequentialHash(b *testing.B) { + tmpDir := b.TempDir() + + // Create test files + for i := 0; i < 50; i++ { + subdir := filepath.Join(tmpDir, "data", string(rune('a'+i%26))) + os.MkdirAll(subdir, 0750) + data := make([]byte, 100*1024) // 100KB each + os.WriteFile(filepath.Join(subdir, "chunk.bin"), data, 0640) + } + + b.ResetTimer() + b.ReportAllocs() + + for i := 0; i < b.N; i++ { + _, err := worker.DirOverallSHA256Hex(tmpDir) + if err != nil { + b.Fatal(err) + } + } +} + +// BenchmarkParallelHash profiles parallel directory hashing +func BenchmarkParallelHash(b *testing.B) { + tmpDir := b.TempDir() + + // Create test files + for i := 0; i < 50; i++ { + subdir := filepath.Join(tmpDir, "data", string(rune('a'+i%26))) + os.MkdirAll(subdir, 0750) + data := make([]byte, 100*1024) // 100KB each + os.WriteFile(filepath.Join(subdir, "chunk.bin"), data, 0640) + } + + b.ResetTimer() + b.ReportAllocs() + + for i := 0; i < b.N; i++ { + _, err := worker.DirOverallSHA256HexParallel(tmpDir) + if err != nil { + b.Fatal(err) + } + } +}