Skip to content

Commit 868cbc5

Browse files
committed
test: add a test to check if the aggregate context is reset between different invocations of a window function and add a check for memory leaks
1 parent 84bf2aa commit 868cbc5

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

test/main.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ int test_execution (void) {
8686

8787
// context
8888
printf("Testing context\n");
89+
8990
rc = db_exec(db, "SELECT js_eval('x = 100;');");
9091
rc = db_exec(db, "SELECT js_eval('x = x*2;');");
9192
rc = db_exec(db, "SELECT js_eval('function test1(n) {return n*x;}');");
@@ -161,6 +162,7 @@ int test_execution (void) {
161162

162163
rc = db_exec(db, "SELECT x, sumint(y) OVER (ORDER BY x ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING) AS sum_y FROM t3 ORDER BY x;");
163164

165+
rc = db_exec(db, "SELECT x, sumint(y) OVER (ORDER BY x ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING) AS sum_y FROM t3 ORDER BY x;");
164166

165167
abort_test:
166168
if (rc != SQLITE_OK) printf("Error: %s\n", sqlite3_errmsg(db));
@@ -172,12 +174,20 @@ int test_execution (void) {
172174

173175
int main (void) {
174176
printf("SQLite-JS version: %s (engine: %s)\n\n", sqlitejs_version(), quickjs_version());
175-
177+
176178
int rc = test_execution();
177-
178179
rc = test_serialization(DB_PATH, false, 1); // create and execute original implementations
179180
rc = test_serialization(DB_PATH, false, 2); // update functions previously registered in the js_functions table
180181
rc = test_serialization(DB_PATH, true, 3); // load the new implementations
181182

183+
sqlite3_int64 current = 0;
184+
sqlite3_int64 highwater = 0;
185+
bool reset = false;
186+
rc = sqlite3_status64(SQLITE_STATUS_MEMORY_USED, &current, &highwater, reset);
187+
if (current > 0) {
188+
printf("memory leak: %lld\n", current);
189+
return 1;
190+
}
191+
182192
return rc;
183193
}

0 commit comments

Comments
 (0)