Debian Codegraph @

bench/trace_test.go

raw
1 //go:build trace
2
3 package bench
4
5 import (
6 "os"
7 "path/filepath"
8 "strings"
9 "testing"
10 )
11
12 func dataDir() string {
13 // data/ is at repo root, bench/ is one level down
14 return filepath.Join("..", "data")
15 }
16
17 func TestLoadTwitterCSV(t *testing.T) {
18 path := filepath.Join(dataDir(), "twitter", "cluster52.csv")
19 if _, err := os.Stat(path); os.IsNotExist(err) {
20 t.Skipf("trace file not found: %s (run fetch-traces.sh)", path)
21 }
22
23 trace, err := LoadCSV(path, ParseTwitter)
24 if err != nil {
25 t.Fatal(err)
26 }
27
28 t.Logf("Twitter cluster52: %d requests, %d unique keys", len(trace.Requests), trace.Unique)
29 for i := 0; i < min(5, len(trace.Requests)); i++ {
30 t.Logf(" [%d] key=%s", i, trace.Requests[i].Key)
31 }
32 }
33
34 func TestLoadMetaCDNCSV(t *testing.T) {
35 dir := filepath.Join(dataDir(), "meta_cdn")
36 entries, err := os.ReadDir(dir)
37 if err != nil || len(entries) == 0 {
38 t.Skipf("no Meta CDN trace files in %s", dir)
39 }
40
41 for _, e := range entries {
42 if e.IsDir() {
43 continue
44 }
45 path := filepath.Join(dir, e.Name())
46 trace, err := LoadCSV(path, ParseMetaCDN)
47 if err != nil {
48 t.Fatal(err)
49 }
50 t.Logf("Meta CDN %s: %d requests, %d unique keys", e.Name(), len(trace.Requests), trace.Unique)
51 for i := 0; i < min(5, len(trace.Requests)); i++ {
52 t.Logf(" [%d] key=%s", i, trace.Requests[i].Key)
53 }
54 return
55 }
56 t.Skip("no CSV files in meta_cdn/")
57 }
58
59 // TestLoadOracleGeneral_All discovers every oracleGeneral file under data/
60 // and verifies the parser can load each one.
61 func TestLoadOracleGeneral_All(t *testing.T) {
62 root := dataDir()
63 if _, err := os.Stat(root); os.IsNotExist(err) {
64 t.Skipf("data directory not found: %s", root)
65 }
66
67 var files []string
68 filepath.WalkDir(root, func(path string, d os.DirEntry, err error) error {
69 if err != nil || d.IsDir() {
70 return nil
71 }
72 if isOracleGeneral(d.Name()) {
73 files = append(files, path)
74 }
75 return nil
76 })
77
78 if len(files) == 0 {
79 t.Skip("no oracleGeneral files found under data/")
80 }
81
82 for _, path := range files {
83 rel, _ := filepath.Rel(root, path)
84 t.Run(rel, func(t *testing.T) {
85 trace, err := LoadOracleGeneral(path)
86 if err != nil {
87 t.Fatal(err)
88 }
89 t.Logf("%d requests, %d unique keys", len(trace.Requests), trace.Unique)
90 for i := 0; i < min(5, len(trace.Requests)); i++ {
91 t.Logf(" [%d] obj_id=%d", i, trace.Requests[i].Key)
92 }
93 })
94 }
95 }
96
97 // isOracleGeneral returns true for files with .oracleGeneral or .oracleGeneral.bin extension.
98 func isOracleGeneral(name string) bool {
99 return strings.HasSuffix(name, ".oracleGeneral") || strings.HasSuffix(name, ".oracleGeneral.bin")
100 }