mirror of
https://github.com/luxfi/graph.git
synced 2026-09-24 00:26:07 +00:00
The write reported nothing, so when it changed no rows in production the pass still printed a clean summary and every swap kept reading zero under a pool claiming thousands in volume. It now returns rows-changed and any error, and the valuation line carries both. Co-authored-by: Hanzo Dev <[email protected]>
43 lines
1.2 KiB
Go
43 lines
1.2 KiB
Go
package storage
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
// The cost of valuing has to stay bounded. The incident this guards against was
|
|
// a pass that never finished, and the reason was that every row went out as its
|
|
// own committed statement. Batched behind one transaction the same rows cost a
|
|
// different order of magnitude — this measures it rather than assuming it.
|
|
func TestValueSwapsCostIsBounded(t *testing.T) {
|
|
const n = 50000
|
|
s, err := New(t.TempDir())
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := s.Init(context.Background()); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
usd := make(map[string]string, n)
|
|
for i := 0; i < n; i++ {
|
|
id := fmt.Sprintf("s%d", i)
|
|
s.SeedSwap(id, &SeedSwapData{Timestamp: int64(i), Pool: "0xpool", AmountUSD: "0"})
|
|
usd[id] = "1.23"
|
|
}
|
|
start := time.Now()
|
|
rows, err := s.ValueSwaps(usd)
|
|
if err != nil {
|
|
t.Fatalf("ValueSwaps: %v", err)
|
|
}
|
|
if rows != int64(n) {
|
|
t.Errorf("changed %d rows, want %d — a write that misses its rows must say so", rows, n)
|
|
}
|
|
took := time.Since(start)
|
|
t.Logf("valued %d swaps in %v (%.1f µs/swap)", n, took, float64(took.Microseconds())/float64(n))
|
|
if took > 10*time.Second {
|
|
t.Errorf("valuing %d swaps took %v — an interval cannot absorb that", n, took)
|
|
}
|
|
}
|