@@ -6,6 +6,10 @@ const fs = require("fs");
66// Access the native module directly for test helpers
77const LbugNative = require ( "../build/lbug_native.js" ) ;
88
9+ // createArrowCSRTestData is only compiled in when the addon is built with
10+ // LBUG_NODEJS_ENABLE_TEST_EXPORTS=ON. Skip the whole suite otherwise.
11+ const hasTestHelpers = typeof LbugNative . createArrowCSRTestData === "function" ;
12+
913let arrowDb , arrowConn ;
1014
1115before ( function ( ) {
@@ -15,12 +19,23 @@ before(function () {
1519 arrowConn = new lbug . Connection ( arrowDb , 2 ) ;
1620} ) ;
1721
22+ after ( function ( ) {
23+ if ( arrowConn ) arrowConn . closeSync ( ) ;
24+ if ( arrowDb ) arrowDb . closeSync ( ) ;
25+ } ) ;
26+
1827describe ( "createArrowRelTableSync CSR" , function ( ) {
28+ before ( function ( ) {
29+ if ( ! hasTestHelpers ) {
30+ this . skip ( ) ;
31+ }
32+ } ) ;
1933 it ( "should throw when dstColName is not a string in CSR mode" , function ( ) {
2034 const { nodeSchemaPtr, nodeArrayPtr, indicesSchemaPtr, indicesArrayPtr,
2135 indptrSchemaPtr, indptrArrayPtr } = LbugNative . createArrowCSRTestData ( "to" ) ;
2236
23- arrowConn . createArrowTableSync ( "person_err" , nodeSchemaPtr , nodeArrayPtr , 1 ) ;
37+ const createPersonResult = arrowConn . createArrowTableSync ( "person_err" , nodeSchemaPtr , nodeArrayPtr , 1 ) ;
38+ createPersonResult . close ( ) ;
2439
2540 assert . throws ( ( ) => {
2641 arrowConn . createArrowRelTableSync (
@@ -36,20 +51,24 @@ describe("createArrowRelTableSync CSR", function () {
3651 const { nodeSchemaPtr, nodeArrayPtr, indicesSchemaPtr, indicesArrayPtr,
3752 indptrSchemaPtr, indptrArrayPtr } = LbugNative . createArrowCSRTestData ( "to" ) ;
3853
39- arrowConn . createArrowTableSync ( "person_default" , nodeSchemaPtr , nodeArrayPtr , 1 ) ;
54+ const createPersonResult = arrowConn . createArrowTableSync ( "person_default" , nodeSchemaPtr , nodeArrayPtr , 1 ) ;
55+ createPersonResult . close ( ) ;
4056
4157 // Use default dstColName "to" (omit last optional param)
42- arrowConn . createArrowRelTableSync (
58+ const createRelResult = arrowConn . createArrowRelTableSync (
4359 "knows_default" , "person_default" , "person_default" ,
4460 indicesSchemaPtr , indicesArrayPtr , 1 ,
4561 indptrSchemaPtr , indptrArrayPtr , 1
4662 ) ;
63+ createRelResult . close ( ) ;
4764
4865 // Verify edges: person0→person1 (w=10), person0→person2 (w=20), person1→person2 (w=30)
49- const rows = arrowConn . querySync (
66+ const qr = arrowConn . querySync (
5067 "MATCH (a:person_default)-[r:knows_default]->(b:person_default) " +
5168 "RETURN a.id, r.weight, b.id ORDER BY a.id, b.id"
52- ) . getAllSync ( ) ;
69+ ) ;
70+ const rows = qr . getAllSync ( ) ;
71+ qr . close ( ) ;
5372
5473 assert . deepEqual (
5574 rows . map ( r => [ Number ( r [ "a.id" ] ) , Number ( r [ "r.weight" ] ) , Number ( r [ "b.id" ] ) ] ) ,
@@ -62,19 +81,23 @@ describe("createArrowRelTableSync CSR", function () {
6281 const { nodeSchemaPtr, nodeArrayPtr, indicesSchemaPtr, indicesArrayPtr,
6382 indptrSchemaPtr, indptrArrayPtr } = LbugNative . createArrowCSRTestData ( dstColName ) ;
6483
65- arrowConn . createArrowTableSync ( "person_custom" , nodeSchemaPtr , nodeArrayPtr , 1 ) ;
84+ const createPersonResult = arrowConn . createArrowTableSync ( "person_custom" , nodeSchemaPtr , nodeArrayPtr , 1 ) ;
85+ createPersonResult . close ( ) ;
6686
67- arrowConn . createArrowRelTableSync (
87+ const createRelResult = arrowConn . createArrowRelTableSync (
6888 "knows_custom" , "person_custom" , "person_custom" ,
6989 indicesSchemaPtr , indicesArrayPtr , 1 ,
7090 indptrSchemaPtr , indptrArrayPtr , 1 ,
7191 dstColName
7292 ) ;
93+ createRelResult . close ( ) ;
7394
74- const rows = arrowConn . querySync (
95+ const qr = arrowConn . querySync (
7596 "MATCH (a:person_custom)-[r:knows_custom]->(b:person_custom) " +
7697 "RETURN a.id, r.weight, b.id ORDER BY a.id, b.id"
77- ) . getAllSync ( ) ;
98+ ) ;
99+ const rows = qr . getAllSync ( ) ;
100+ qr . close ( ) ;
78101
79102 assert . deepEqual (
80103 rows . map ( r => [ Number ( r [ "a.id" ] ) , Number ( r [ "r.weight" ] ) , Number ( r [ "b.id" ] ) ] ) ,
@@ -86,7 +109,8 @@ describe("createArrowRelTableSync CSR", function () {
86109 // Fresh data since each call to createArrowTableSync transfers ownership
87110 const d = LbugNative . createArrowCSRTestData ( "to" ) ;
88111
89- arrowConn . createArrowTableSync ( "person_flat_test" , d . nodeSchemaPtr , d . nodeArrayPtr , 1 ) ;
112+ const createPersonResult = arrowConn . createArrowTableSync ( "person_flat_test" , d . nodeSchemaPtr , d . nodeArrayPtr , 1 ) ;
113+ createPersonResult . close ( ) ;
90114
91115 // Flat path requires "from"/"to" columns in the Arrow batch.
92116 // Passing a batch with only "id" should trigger a Ladybug error (confirming flat path is used).
0 commit comments