Skip to content

Commit db40625

Browse files
committed
fix test
1 parent a21575a commit db40625

File tree

1 file changed

+49
-11
lines changed

1 file changed

+49
-11
lines changed

test/integration/v2/stream.test.ts

Lines changed: 49 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import exp from "node:constants";
22
import { Firebolt } from "../../../src";
33
import stream, { TransformCallback } from "node:stream";
4+
import BigNumber from "bignumber.js";
45

56
const connectionParams = {
67
auth: {
@@ -264,7 +265,7 @@ describe("streams", () => {
264265
i as id,
265266
'user_' || i::string as username,
266267
'email_' || i::string || '@example.com' as email,
267-
CASE WHEN i % 2 = 0 THEN 'active' ELSE 'inactive' END as status,
268+
CASE WHEN i % 2 = 0 THEN true ELSE false END as status,
268269
CAST('100000000000000000' as BIGINT) as big_number,
269270
'2024-01-01'::date + (i % 365) as created_date,
270271
RANDOM() * 1000 as score,
@@ -284,6 +285,20 @@ describe("streams", () => {
284285

285286
const { data } = await statement.streamResult();
286287

288+
// Add meta event handler to verify column metadata
289+
data.on("meta", m => {
290+
expect(m).toEqual([
291+
{ name: "id", type: "int" },
292+
{ name: "username", type: "text" },
293+
{ name: "email", type: "text" },
294+
{ name: "status", type: "boolean" },
295+
{ name: "big_number", type: "long" },
296+
{ name: "created_date", type: "date" },
297+
{ name: "score", type: "double" },
298+
{ name: "description", type: "text" }
299+
]);
300+
});
301+
287302
// Buffer pool configuration
288303
const poolSize = 8192; // 8KB
289304
const poolBuffer = Buffer.allocUnsafe(poolSize);
@@ -311,17 +326,40 @@ describe("streams", () => {
311326
maxMemoryUsed = Math.max(maxMemoryUsed, currentMemory.heapUsed);
312327
}
313328

314-
// Verify data types are correct for normalized data
329+
// Verify data types are correct for normalized data on first row
315330
if (rowCount === 1) {
316331
const typedRow = row as Record<string, unknown>;
317-
expect(typeof typedRow.id).toBe("number");
318-
expect(typeof typedRow.username).toBe("string");
319-
expect(typeof typedRow.email).toBe("string");
320-
expect(typeof typedRow.status).toBe("string");
321-
expect(typeof typedRow.big_number).toBe("number");
322-
expect(typedRow.created_date instanceof Date).toBe(true);
323-
expect(typeof typedRow.score).toBe("number");
324-
expect(typeof typedRow.description).toBe("string");
332+
333+
// Verify actual values for first row
334+
expect(typedRow.id).toBe(1);
335+
expect(typedRow.username).toBe("user_1");
336+
expect(typedRow.email).toBe("[email protected]");
337+
expect(typedRow.status).toBe(false); // i=1, 1%2=1, so false
338+
expect(typedRow.big_number).toEqual(
339+
new BigNumber("100000000000000000")
340+
);
341+
expect(typedRow.created_date).toEqual(new Date("2024-01-02")); // 2024-01-01 + 1 day
342+
expect(typedRow.description).toBe(
343+
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."
344+
);
345+
}
346+
347+
// Verify data types are correct for normalized data on last row
348+
if (rowCount === seriesNum) {
349+
const typedRow = row as Record<string, unknown>;
350+
351+
// Verify actual values for last row
352+
expect(typedRow.id).toBe(seriesNum);
353+
expect(typedRow.username).toBe(`user_${seriesNum}`);
354+
expect(typedRow.email).toBe(`email_${seriesNum}@example.com`);
355+
expect(typedRow.status).toBe(true); // seriesNum=100000, 100000%2=0, so true
356+
expect(typedRow.big_number).toEqual(
357+
new BigNumber("100000000000000000")
358+
);
359+
expect(typedRow.created_date).toEqual(new Date("2024-12-21")); // 2024-01-01 + (100000 % 365) = 2024-01-01 + 269 days
360+
expect(typedRow.description).toBe(
361+
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."
362+
);
325363
}
326364

327365
const json = JSON.stringify(row);
@@ -377,7 +415,7 @@ describe("streams", () => {
377415
// Memory usage should remain reasonable with proper streaming
378416
const memoryGrowth =
379417
(maxMemoryUsed - initialMemory.heapUsed) / (1024 * 1024);
380-
expect(memoryGrowth).toBeLessThan(100); // Allow reasonable memory for complex data types with various field types
418+
expect(memoryGrowth).toBeLessThan(120); // Allow reasonable memory for complex data types with various field types
381419

382420
console.log(
383421
`Data types streaming test: processed ${rowCount} rows with various data types, ` +

0 commit comments

Comments
 (0)