Ship live alerts, pool status, AI monitor, remote agent commands, build manager, and uninstall flow; wire Calibrate settings (WS ping, pool traffic log, retention limits) at runtime and exclude server/data from git.
34 lines
669 B
Go
34 lines
669 B
Go
package db
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestPurgeHashrateSamplesBefore(t *testing.T) {
|
|
d, err := New(t.TempDir())
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer d.Close()
|
|
|
|
_, err = d.Exec("INSERT INTO hashrate_samples (agent_id, hashrate, timestamp) VALUES ('a1', 100, ?)",
|
|
time.Now().Add(-48*time.Hour))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
_, err = d.Exec("INSERT INTO hashrate_samples (agent_id, hashrate, timestamp) VALUES ('a1', 200, ?)",
|
|
time.Now())
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
n, err := d.PurgeHashrateSamplesBefore(time.Now().Add(-24 * time.Hour))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if n != 1 {
|
|
t.Fatalf("expected 1 purged, got %d", n)
|
|
}
|
|
}
|