Skip to content

Commit 934d2b5

Browse files
committed
simplify tests
1 parent 8a47b9f commit 934d2b5

File tree

1 file changed

+24
-55
lines changed

1 file changed

+24
-55
lines changed

internal/rows/arrowbased/batchloader_test.go

Lines changed: 24 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -255,31 +255,13 @@ func TestCloudFetchIterator(t *testing.T) {
255255
})
256256

257257
t.Run("should use custom Transport when provided", func(t *testing.T) {
258-
customTransport := &http.Transport{
259-
MaxIdleConns: 10,
260-
MaxIdleConnsPerHost: 5,
261-
}
262-
requestCount := 0
263-
264258
handler = func(w http.ResponseWriter, r *http.Request) {
265-
requestCount++
266259
w.WriteHeader(http.StatusOK)
267-
_, err := w.Write(generateMockArrowBytes(generateArrowRecord()))
268-
if err != nil {
269-
panic(err)
270-
}
260+
w.Write(generateMockArrowBytes(generateArrowRecord()))
271261
}
272262

273263
startRowOffset := int64(100)
274-
275-
links := []*cli_service.TSparkArrowResultLink{
276-
{
277-
FileLink: server.URL,
278-
ExpiryTime: time.Now().Add(10 * time.Minute).Unix(),
279-
StartRowOffset: startRowOffset,
280-
RowCount: 1,
281-
},
282-
}
264+
customTransport := &http.Transport{MaxIdleConns: 10}
283265

284266
cfg := config.WithDefaults()
285267
cfg.UseLz4Compression = false
@@ -288,70 +270,57 @@ func TestCloudFetchIterator(t *testing.T) {
288270

289271
bi, err := NewCloudBatchIterator(
290272
context.Background(),
291-
links,
273+
[]*cli_service.TSparkArrowResultLink{{
274+
FileLink: server.URL,
275+
ExpiryTime: time.Now().Add(10 * time.Minute).Unix(),
276+
StartRowOffset: startRowOffset,
277+
RowCount: 1,
278+
}},
292279
startRowOffset,
293280
cfg,
294281
)
295282
assert.Nil(t, err)
296283

297-
// Verify custom transport is passed through the iterator chain
298-
wrapper, ok := bi.(*batchIterator)
299-
assert.True(t, ok)
300-
cbi, ok := wrapper.ipcIterator.(*cloudIPCStreamIterator)
301-
assert.True(t, ok)
284+
cbi := bi.(*batchIterator).ipcIterator.(*cloudIPCStreamIterator)
302285
assert.Equal(t, customTransport, cbi.transport)
303286

304-
// Fetch should work with custom transport
305-
sab1, nextErr := bi.Next()
287+
// Verify fetch works
288+
sab, nextErr := bi.Next()
306289
assert.Nil(t, nextErr)
307-
assert.NotNil(t, sab1)
308-
assert.Greater(t, requestCount, 0) // Verify request was made
290+
assert.NotNil(t, sab)
309291
})
310292

311-
t.Run("should use http.DefaultClient when Transport is nil", func(t *testing.T) {
293+
t.Run("should fallback to http.DefaultClient when Transport is nil", func(t *testing.T) {
312294
handler = func(w http.ResponseWriter, r *http.Request) {
313295
w.WriteHeader(http.StatusOK)
314-
_, err := w.Write(generateMockArrowBytes(generateArrowRecord()))
315-
if err != nil {
316-
panic(err)
317-
}
296+
w.Write(generateMockArrowBytes(generateArrowRecord()))
318297
}
319298

320299
startRowOffset := int64(100)
321-
322-
links := []*cli_service.TSparkArrowResultLink{
323-
{
324-
FileLink: server.URL,
325-
ExpiryTime: time.Now().Add(10 * time.Minute).Unix(),
326-
StartRowOffset: startRowOffset,
327-
RowCount: 1,
328-
},
329-
}
330-
331300
cfg := config.WithDefaults()
332301
cfg.UseLz4Compression = false
333302
cfg.MaxDownloadThreads = 1
334-
// Transport is nil by default
335303

336304
bi, err := NewCloudBatchIterator(
337305
context.Background(),
338-
links,
306+
[]*cli_service.TSparkArrowResultLink{{
307+
FileLink: server.URL,
308+
ExpiryTime: time.Now().Add(10 * time.Minute).Unix(),
309+
StartRowOffset: startRowOffset,
310+
RowCount: 1,
311+
}},
339312
startRowOffset,
340313
cfg,
341314
)
342315
assert.Nil(t, err)
343316

344-
// Verify nil transport is passed through
345-
wrapper, ok := bi.(*batchIterator)
346-
assert.True(t, ok)
347-
cbi, ok := wrapper.ipcIterator.(*cloudIPCStreamIterator)
348-
assert.True(t, ok)
317+
cbi := bi.(*batchIterator).ipcIterator.(*cloudIPCStreamIterator)
349318
assert.Nil(t, cbi.transport)
350319

351-
// Fetch should work (falls back to http.DefaultClient)
352-
sab1, nextErr := bi.Next()
320+
// Verify fetch works with default client
321+
sab, nextErr := bi.Next()
353322
assert.Nil(t, nextErr)
354-
assert.NotNil(t, sab1)
323+
assert.NotNil(t, sab)
355324
})
356325
}
357326

0 commit comments

Comments
 (0)