fetch_ml/scripts/testing/test-native-with-redis.sh
Jeremie Fraeys 4730f82236
feat(scripts/testing): support both C++ and Rust native libraries in Redis tests
Update test-native-with-redis.sh to detect and use both native implementations:

- Extend library detection to check both native/build/ (C++) and native_rust/target/release/ (Rust)

- Default to building Rust libraries if neither found (make rust-build)

- Check for .so (Linux) and .dylib (macOS) extensions for both implementations
2026-03-23 15:22:29 -04:00

56 lines
1.5 KiB
Bash
Executable file

#!/bin/bash
# Test script for native libraries with Redis via docker compose
# Usage: ./scripts/test-native-with-redis.sh
set -e
echo "=== FetchML Native Library Test with Redis ==="
echo ""
# Check if C++ or Rust native libraries are built
if [ ! -f "native/build/libqueue_index.so" ] && [ ! -f "native/build/libqueue_index.dylib" ] && \
[ ! -f "native_rust/target/release/libqueue_index.so" ] && [ ! -f "native_rust/target/release/libqueue_index.dylib" ]; then
echo "Building Rust native libraries..."
make rust-build
fi
compose_cmd=$(command -v docker compose >/dev/null 2>&1 && echo "docker compose" || echo "docker compose")
# Start Redis via docker compose
echo "Starting Redis..."
cd deployments
$compose_cmd -f docker compose.dev.yml up -d redis
cd ..
# Wait for Redis to be ready
echo "Waiting for Redis to be ready..."
sleep 2
until docker exec ml-experiments-redis redis-cli ping | grep -q PONG; do
echo " Redis not ready yet, waiting..."
sleep 1
done
echo " Redis is ready!"
echo ""
# Run tests with native_libs build tag
echo "Running tests with -tags native_libs..."
CGO_ENABLED=1 go test -tags native_libs -v ./tests/benchmarks/... 2>&1 | head -100
TEST_EXIT=${PIPESTATUS[0]}
echo ""
echo "=== Test Summary ==="
if [ $TEST_EXIT -eq 0 ]; then
echo "✅ All tests passed with native libraries enabled"
else
echo "❌ Tests failed with exit code: $TEST_EXIT"
fi
# Cleanup
echo ""
echo "Stopping Redis..."
cd deployments
$compose_cmd -f docker compose.dev.yml stop redis
cd ..
exit $TEST_EXIT