@@ -37,16 +37,18 @@ func TestMemoryTrackerTrack(t *testing.T) {
3737 }
3838 })
3939
40- t .Run ("call_inputs_combined_watermark" , func (t * testing.T ) {
41- // Models the inputs to a.join(', ') where the list and separator coexist.
40+ t .Run ("consecutive_watermarks" , func (t * testing.T ) {
4241 tracker := NewMemoryTracker ()
43- list := NewRefValList (adapter , []ref.Val {String ("a" ), String ("b" )})
44- sep := String (", " )
45- if got := tracker .Track (list , sep ); got != 4 {
46- t .Errorf ("Track(list, sep) got %d, want 4 (3 list + 1 separator)" , got )
42+ list := NewRefValList (adapter , []ref.Val {Int (1 ), Int (2 )})
43+ if got := tracker .Track (list ); got != 3 {
44+ t .Errorf ("Track(list) got %d, want 3" , got )
4745 }
48- if got := tracker .Peak (); got != 4 {
49- t .Errorf ("Peak() got %d, want 4" , got )
46+ arg := Int (0 )
47+ if got := tracker .Track (arg ); got != 1 {
48+ t .Errorf ("Track(arg) got %d, want 1" , got )
49+ }
50+ if got := tracker .Peak (); got != 3 {
51+ t .Errorf ("Peak() got %d, want 3" , got )
5052 }
5153 })
5254
@@ -63,18 +65,18 @@ func TestMemoryTrackerTrack(t *testing.T) {
6365 // Models the output of a + a, a string twice the size of its inputs.
6466 tracker := NewMemoryTracker ()
6567 in := String (strings .Repeat ("a" , 50 ))
66- tracker .Track (in , in )
68+ tracker .Track (in )
6769 out := String (strings .Repeat ("a" , 100 ))
6870 tracker .Track (out )
6971 if got := tracker .Peak (); got != 10 {
7072 t .Errorf ("Peak() got %d, want 10 (100-char output at 10 chars per unit)" , got )
7173 }
7274 })
7375
74- t .Run ("saturating_sum " , func (t * testing.T ) {
76+ t .Run ("saturating_value " , func (t * testing.T ) {
7577 tracker := NewMemoryTracker ()
7678 big := customSizerVal (math .MaxUint32 )
77- if got := tracker .Track (big , big ); got != math .MaxUint32 {
79+ if got := tracker .Track (big ); got != math .MaxUint32 {
7880 t .Errorf ("Track() got %d, want MaxUint32" , got )
7981 }
8082 if got := tracker .Peak (); got != math .MaxUint32 {
@@ -104,7 +106,7 @@ func TestMemoryTrackerSample(t *testing.T) {
104106 t .Run ("default_interval_samples_every_value" , func (t * testing.T ) {
105107 tracker := NewMemoryTracker ()
106108 for i := 0 ; i < 3 ; i ++ {
107- if got := tracker .Sample (Int (i )); got != 1 {
109+ if got := tracker .Sample (1 , Int (i )); got != 1 {
108110 t .Errorf ("Sample() got %d, want 1" , got )
109111 }
110112 }
@@ -116,23 +118,48 @@ func TestMemoryTrackerSample(t *testing.T) {
116118 t .Run ("interval_skips_intermediate_samples" , func (t * testing.T ) {
117119 tracker := NewMemoryTracker (MemoryTrackerSampleInterval (3 ))
118120 list := NewRefValList (adapter , []ref.Val {Int (1 ), Int (2 )})
119- if got := tracker .Sample (list ); got != 0 {
120- t .Errorf ("Sample() #1 got %d, want 0 (skipped )" , got )
121+ if got := tracker .Sample (1 , list ); got != 3 {
122+ t .Errorf ("Sample() #1 got %d, want 3 (computed on first observation )" , got )
121123 }
122- if got := tracker .Sample (list ); got != 0 {
124+ if got := tracker .Sample (1 , list ); got != 0 {
123125 t .Errorf ("Sample() #2 got %d, want 0 (skipped)" , got )
124126 }
125- if got := tracker .Sample (list ); got != 3 {
127+ if got := tracker .Sample (1 , list ); got != 3 {
126128 t .Errorf ("Sample() #3 got %d, want 3 (computed)" , got )
127129 }
128130 if got := tracker .Peak (); got != 3 {
129131 t .Errorf ("Peak() got %d, want 3" , got )
130132 }
131133 })
132134
135+ t .Run ("per_id_tracking" , func (t * testing.T ) {
136+ tracker := NewMemoryTracker (MemoryTrackerSampleInterval (2 ))
137+ list := NewRefValList (adapter , []ref.Val {Int (1 ), Int (2 )})
138+ // id 1: sample 1 (computed on first observation)
139+ if got := tracker .Sample (1 , list ); got != 3 {
140+ t .Errorf ("Sample(1) #1 got %d, want 3" , got )
141+ }
142+ // id 2: sample 1 (computed on first observation)
143+ if got := tracker .Sample (2 , list ); got != 3 {
144+ t .Errorf ("Sample(2) #1 got %d, want 3" , got )
145+ }
146+ // id 1: sample 2 (computed, multiple of 2)
147+ if got := tracker .Sample (1 , list ); got != 3 {
148+ t .Errorf ("Sample(1) #2 got %d, want 3" , got )
149+ }
150+ // id 2: sample 2 (computed, multiple of 2)
151+ if got := tracker .Sample (2 , list ); got != 3 {
152+ t .Errorf ("Sample(2) #2 got %d, want 3" , got )
153+ }
154+ // id 1: sample 3 (skipped)
155+ if got := tracker .Sample (1 , list ); got != 0 {
156+ t .Errorf ("Sample(1) #3 got %d, want 0" , got )
157+ }
158+ })
159+
133160 t .Run ("zero_interval_clamped_to_one" , func (t * testing.T ) {
134161 tracker := NewMemoryTracker (MemoryTrackerSampleInterval (0 ))
135- if got := tracker .Sample (Int (1 )); got != 1 {
162+ if got := tracker .Sample (1 , Int (1 )); got != 1 {
136163 t .Errorf ("Sample() got %d, want 1" , got )
137164 }
138165 })
@@ -172,4 +199,5 @@ func TestMemoryTrackerVersion(t *testing.T) {
172199
173200// Interface conformance check: the tracker's calculator remains usable as an AggregateSizer
174201// by visitor implementations.
202+ var _ ref.Val = customSizerVal (0 )
175203var _ traits.Sizer = customSizerVal (0 )
0 commit comments