Commit fbbc5a6
authored
attribute: make TestHashKVs linear-time (#8204)
Unblocks #8166
Per
#8166 (comment)
## Why
This updates `TestHashKVsEquality` to avoid the quadratic pairwise
comparison that was causing slow runs and timeouts in CI.
Below are the results from my machine.
Old:
```
$ go test -run=TestHashKVs -count=1
PASS
ok go.opentelemetry.io/otel/attribute 2.063s
```
New:
```
$ go test -run=TestHashKVs -count=1
PASS
ok go.opentelemetry.io/otel/attribute 0.024s
```
Instead of collecting every generated testcase and comparing each hash
against every other hash, the test now checks uniqueness as each case is
generated by storing previously seen hashes in a map. Note that it also
does not use the equality operator of `KeyValue` to determine if the
hash should be equal or different.
## What
- Rename the test from `TestHashKVsEquality` to `TestHashKVs`
- Replace the O(n^2) post-processing loop with an O(n) streaming
uniqueness check
- Simplify failure reporting by removing the dedicated `msg` helper
Side note: for me it also makes the test more readable (however, this is
opinionated).1 parent 3ee1d5a commit fbbc5a6
1 file changed
Lines changed: 24 additions & 45 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
44 | | - | |
| 44 | + | |
45 | 45 | | |
| 46 | + | |
46 | 47 | | |
47 | 48 | | |
48 | 49 | | |
49 | 50 | | |
50 | 51 | | |
51 | 52 | | |
52 | | - | |
53 | | - | |
54 | | - | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
55 | 69 | | |
56 | | - | |
| 70 | + | |
| 71 | + | |
57 | 72 | | |
| 73 | + | |
58 | 74 | | |
59 | 75 | | |
60 | 76 | | |
61 | | - | |
62 | | - | |
| 77 | + | |
63 | 78 | | |
64 | 79 | | |
65 | 80 | | |
66 | 81 | | |
67 | 82 | | |
68 | 83 | | |
69 | | - | |
70 | | - | |
| 84 | + | |
71 | 85 | | |
72 | 86 | | |
73 | 87 | | |
74 | 88 | | |
75 | 89 | | |
76 | 90 | | |
77 | 91 | | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
| 92 | + | |
100 | 93 | | |
101 | 94 | | |
102 | 95 | | |
103 | 96 | | |
104 | 97 | | |
105 | 98 | | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | 99 | | |
121 | 100 | | |
122 | 101 | | |
| |||
0 commit comments