@@ -65,7 +65,11 @@ func TestMarginInfoUpdater_GetMaxBorrowable(t *testing.T) {
6565 svc := newMockMarginBorrowRepayService (map [string ]fixedpoint.Value {
6666 "BTC" : fixedpoint .NewFromFloat (1.5 ),
6767 })
68- updater := NewMarginInfoUpdater (svc )
68+ config := MarginInfoUpdaterConfig {
69+ BatchSize : 1 ,
70+ }
71+ config .Defaults ()
72+ updater := NewMarginInfoUpdater (svc , config )
6973
7074 t .Run ("untracked asset is not found" , func (t * testing.T ) {
7175 amount , ok := updater .GetMaxBorrowable ("BTC" )
@@ -82,7 +86,7 @@ func TestMarginInfoUpdater_GetMaxBorrowable(t *testing.T) {
8286 })
8387
8488 t .Run ("reports the queried amount after Update" , func (t * testing.T ) {
85- updater .Update (context .Background (), 1 )
89+ updater .Update (context .Background ())
8690
8791 amount , ok := updater .GetMaxBorrowable ("BTC" )
8892 assert .True (t , ok )
@@ -97,8 +101,12 @@ func TestMarginInfoUpdater_Update(t *testing.T) {
97101 "ETH" : fixedpoint .NewFromFloat (2 ),
98102 "SOL" : fixedpoint .NewFromFloat (3 ),
99103 }
104+ config := MarginInfoUpdaterConfig {
105+ BatchSize : len (values ),
106+ }
107+ config .Defaults ()
100108 svc := newMockMarginBorrowRepayService (values )
101- updater := NewMarginInfoUpdater (svc )
109+ updater := NewMarginInfoUpdater (svc , config )
102110
103111 emitted := map [string ]fixedpoint.Value {}
104112 updater .OnMaxBorrowable (func (asset string , amount fixedpoint.Value ) {
@@ -110,7 +118,7 @@ func TestMarginInfoUpdater_Update(t *testing.T) {
110118 }
111119
112120 // batch size >= number of assets => all done in one pass
113- updater .Update (context .Background (), len ( values ) )
121+ updater .Update (context .Background ())
114122
115123 for asset , want := range values {
116124 amount , ok := updater .GetMaxBorrowable (asset )
@@ -133,7 +141,11 @@ func TestMarginInfoUpdater_Update(t *testing.T) {
133141 }
134142
135143 svc := newMockMarginBorrowRepayService (values )
136- updater := NewMarginInfoUpdater (svc )
144+ config := MarginInfoUpdaterConfig {
145+ BatchSize : batchSize ,
146+ }
147+ config .Defaults ()
148+ updater := NewMarginInfoUpdater (svc , config )
137149
138150 emitCount := map [string ]int {}
139151 updater .OnMaxBorrowable (func (asset string , amount fixedpoint.Value ) {
@@ -145,13 +157,13 @@ func TestMarginInfoUpdater_Update(t *testing.T) {
145157 }
146158
147159 // A single Update only processes batchSize assets.
148- updater .Update (context .Background (), batchSize )
160+ updater .Update (context .Background ())
149161 assert .Len (t , updater .doneAssets , batchSize , "only one batch processed per Update" )
150162
151163 // ceil(5/2) = 3 Update calls are needed to cover every asset. Run the two
152164 // remaining passes to complete the cycle.
153- updater .Update (context .Background (), batchSize )
154- updater .Update (context .Background (), batchSize )
165+ updater .Update (context .Background ())
166+ updater .Update (context .Background ())
155167
156168 // Every asset must have been refreshed exactly once with the correct value.
157169 for asset , want := range values {
@@ -175,18 +187,22 @@ func TestMarginInfoUpdater_Update(t *testing.T) {
175187 "SOL" : fixedpoint .NewFromFloat (3 ),
176188 }
177189 svc := newMockMarginBorrowRepayService (values )
178- updater := NewMarginInfoUpdater (svc )
190+ config := MarginInfoUpdaterConfig {
191+ BatchSize : len (values ),
192+ }
193+ config .Defaults ()
194+ updater := NewMarginInfoUpdater (svc , config )
179195
180196 for asset := range values {
181197 updater .AddBorrowableAssets (asset )
182198 }
183199
184200 // first cycle
185- updater .Update (context .Background (), len ( values ) )
201+ updater .Update (context .Background ())
186202 assert .Empty (t , updater .doneAssets , "cycle completes and resets" )
187203
188204 // second cycle: each asset should be queried again
189- updater .Update (context .Background (), len ( values ) )
205+ updater .Update (context .Background ())
190206 for asset := range values {
191207 assert .Equal (t , 2 , svc .getQueryCount (asset ), "queried again in the next cycle: %s" , asset )
192208 }
@@ -199,7 +215,11 @@ func TestMarginInfoUpdater_Update(t *testing.T) {
199215 }
200216 svc := newMockMarginBorrowRepayService (values )
201217 svc .errs ["ETH" ] = fmt .Errorf ("boom" )
202- updater := NewMarginInfoUpdater (svc )
218+ config := MarginInfoUpdaterConfig {
219+ BatchSize : 10 ,
220+ }
221+ config .Defaults ()
222+ updater := NewMarginInfoUpdater (svc , config )
203223
204224 emitted := map [string ]fixedpoint.Value {}
205225 updater .OnMaxBorrowable (func (asset string , amount fixedpoint.Value ) {
@@ -209,7 +229,7 @@ func TestMarginInfoUpdater_Update(t *testing.T) {
209229 updater .AddBorrowableAssets ("BTC" , "ETH" )
210230
211231 // large batch so both are attempted in one pass
212- updater .Update (context .Background (), 10 )
232+ updater .Update (context .Background ())
213233
214234 // BTC succeeded; ETH errored so it is neither recorded as done nor emitted.
215235 btc , ok := updater .GetMaxBorrowable ("BTC" )
@@ -228,7 +248,7 @@ func TestMarginInfoUpdater_Update(t *testing.T) {
228248 delete (svc .errs , "ETH" )
229249 svc .mu .Unlock ()
230250
231- updater .Update (context .Background (), 10 )
251+ updater .Update (context .Background ())
232252 eth , ok := updater .GetMaxBorrowable ("ETH" )
233253 assert .True (t , ok )
234254 assert .Equal (t , "2" , eth .String ())
@@ -238,10 +258,13 @@ func TestMarginInfoUpdater_Update(t *testing.T) {
238258
239259 t .Run ("no assets is a no-op" , func (t * testing.T ) {
240260 svc := newMockMarginBorrowRepayService (nil )
241- updater := NewMarginInfoUpdater (svc )
261+ config := MarginInfoUpdaterConfig {
262+ BatchSize : 5 ,
263+ }
264+ updater := NewMarginInfoUpdater (svc , config )
242265
243266 assert .NotPanics (t , func () {
244- updater .Update (context .Background (), 5 )
267+ updater .Update (context .Background ())
245268 })
246269 })
247270}
0 commit comments