Move unit tests from tests/unit/ to internal/ following Go conventions: Security tests: - tests/unit/security/* -> internal/security/* (audit, config_integrity, filetype, gpu_audit, hipaa_validation, manifest_filename, path_traversal, resource_quota, secrets) Storage tests: - tests/unit/storage/* -> internal/storage/* (db, experiment_metadata) Telemetry tests: - tests/unit/telemetry/* -> internal/telemetry/* (telemetry) Tracking tests: - tests/unit/reproducibility/* -> internal/tracking/* (config_hash, environment_capture) Worker tests: - tests/unit/worker/* -> internal/worker/* (artifacts, config, hash_bench, plugins/jupyter_task, plugins/vllm, prewarm_v1, run_manifest_execution, snapshot_stage, snapshot_store, worker) Update import paths in test files to reflect new locations.
121 lines
2.4 KiB
Go
121 lines
2.4 KiB
Go
package telemetry_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/jfraeys/fetch_ml/internal/telemetry"
|
|
)
|
|
|
|
func TestDiffIO(t *testing.T) {
|
|
t.Parallel() // Enable parallel execution
|
|
|
|
// Test normal case where after > before
|
|
before := telemetry.IOStats{
|
|
ReadBytes: 1000,
|
|
WriteBytes: 500,
|
|
}
|
|
|
|
after := telemetry.IOStats{
|
|
ReadBytes: 1500,
|
|
WriteBytes: 800,
|
|
}
|
|
|
|
delta := telemetry.DiffIO(before, after)
|
|
|
|
if delta.ReadBytes != 500 {
|
|
t.Errorf("Expected read delta 500, got %d", delta.ReadBytes)
|
|
}
|
|
|
|
if delta.WriteBytes != 300 {
|
|
t.Errorf("Expected write delta 300, got %d", delta.WriteBytes)
|
|
}
|
|
}
|
|
|
|
func TestDiffIOZero(t *testing.T) {
|
|
t.Parallel() // Enable parallel execution
|
|
|
|
// Test case where no change
|
|
stats := telemetry.IOStats{
|
|
ReadBytes: 1000,
|
|
WriteBytes: 500,
|
|
}
|
|
|
|
delta := telemetry.DiffIO(stats, stats)
|
|
|
|
if delta.ReadBytes != 0 {
|
|
t.Errorf("Expected read delta 0, got %d", delta.ReadBytes)
|
|
}
|
|
|
|
if delta.WriteBytes != 0 {
|
|
t.Errorf("Expected write delta 0, got %d", delta.WriteBytes)
|
|
}
|
|
}
|
|
|
|
func TestDiffIONegative(t *testing.T) {
|
|
t.Parallel() // Enable parallel execution
|
|
|
|
// Test case where after < before (should result in 0)
|
|
before := telemetry.IOStats{
|
|
ReadBytes: 1500,
|
|
WriteBytes: 800,
|
|
}
|
|
|
|
after := telemetry.IOStats{
|
|
ReadBytes: 1000,
|
|
WriteBytes: 500,
|
|
}
|
|
|
|
delta := telemetry.DiffIO(before, after)
|
|
|
|
// Should be 0 when after < before
|
|
if delta.ReadBytes != 0 {
|
|
t.Errorf("Expected read delta 0, got %d", delta.ReadBytes)
|
|
}
|
|
|
|
if delta.WriteBytes != 0 {
|
|
t.Errorf("Expected write delta 0, got %d", delta.WriteBytes)
|
|
}
|
|
}
|
|
|
|
func TestDiffIOEmpty(t *testing.T) {
|
|
t.Parallel() // Enable parallel execution
|
|
|
|
// Test case with empty stats
|
|
before := telemetry.IOStats{}
|
|
after := telemetry.IOStats{
|
|
ReadBytes: 1000,
|
|
WriteBytes: 500,
|
|
}
|
|
|
|
delta := telemetry.DiffIO(before, after)
|
|
|
|
if delta.ReadBytes != 1000 {
|
|
t.Errorf("Expected read delta 1000, got %d", delta.ReadBytes)
|
|
}
|
|
|
|
if delta.WriteBytes != 500 {
|
|
t.Errorf("Expected write delta 500, got %d", delta.WriteBytes)
|
|
}
|
|
}
|
|
|
|
func TestDiffIOReverse(t *testing.T) {
|
|
t.Parallel() // Enable parallel execution
|
|
|
|
// Test case with empty stats
|
|
before := telemetry.IOStats{
|
|
ReadBytes: 1000,
|
|
WriteBytes: 500,
|
|
}
|
|
after := telemetry.IOStats{}
|
|
|
|
delta := telemetry.DiffIO(before, after)
|
|
|
|
// Should be 0 when after < before
|
|
if delta.ReadBytes != 0 {
|
|
t.Errorf("Expected read delta 0, got %d", delta.ReadBytes)
|
|
}
|
|
|
|
if delta.WriteBytes != 0 {
|
|
t.Errorf("Expected write delta 0, got %d", delta.WriteBytes)
|
|
}
|
|
}
|