Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pending result tests #17

Merged
merged 3 commits into from
Oct 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 95 additions & 0 deletions bindings/test/pending.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import duckdb from '@duckdb/node-bindings';
import { expect, suite, test } from 'vitest';
import { expectResult } from './utils/expectResult';
import { BIGINT, INTEGER } from './utils/expectedLogicalTypes';
import { data } from './utils/expectedVectors';
import { sleep } from './utils/sleep';
import { withConnection } from './utils/withConnection';

suite('pending', () => {
test('execute', async () => {
await withConnection(async (connection) => {
const prepared = await duckdb.prepare(connection, 'select 11 as a');
try {
const pending = duckdb.pending_prepared(prepared);
try {
const result = await duckdb.execute_pending(pending);
try {
await expectResult(result, {
columns: [
{ name: 'a', logicalType: INTEGER },
],
chunks: [
{ rowCount: 1, vectors: [data(4, [true], [11])]},
],
});
} finally {
duckdb.destroy_result(result);
}
} finally {
duckdb.destroy_pending(pending);
}
} finally {
duckdb.destroy_prepare(prepared);
}
});
});
test('tasks', async () => {
await withConnection(async (connection) => {
const prepared = await duckdb.prepare(connection, 'select count(*) as count from range(10_000)');
try {
const pending = duckdb.pending_prepared(prepared);
try {
let pending_state = duckdb.pending_execute_check_state(pending);
while (!duckdb.pending_execution_is_finished(pending_state)) {
pending_state = duckdb.pending_execute_task(pending);
await sleep(0); // yield to allow progress
}
const result = await duckdb.execute_pending(pending);
try {
await expectResult(result, {
columns: [
{ name: 'count', logicalType: BIGINT },
],
chunks: [
{ rowCount: 1, vectors: [data(8, [true], [10_000n])]},
],
});
} finally {
duckdb.destroy_result(result);
}
} finally {
duckdb.destroy_pending(pending);
}
} finally {
duckdb.destroy_prepare(prepared);
}
});
});
test('interrupt', async () => {
await withConnection(async (connection) => {
const prepared = await duckdb.prepare(connection, 'select count(*) as count from range(10_000)');
try {
const pending = duckdb.pending_prepared(prepared);
try {
duckdb.interrupt(connection);
await sleep(0); // yield to allow progress

let pending_state = duckdb.pending_execute_check_state(pending);
while (!duckdb.pending_execution_is_finished(pending_state)) {
pending_state = duckdb.pending_execute_task(pending);
await sleep(0); // yield to allow progress
}

expect(pending_state).toBe(duckdb.PendingState.ERROR);
expect(duckdb.pending_error(pending)).toBe('INTERRUPT Error: Interrupted!');
} finally {
duckdb.destroy_pending(pending);
}
} finally {
duckdb.destroy_prepare(prepared);
}
});
});
// TODO: query progress?
});
2 changes: 0 additions & 2 deletions bindings/test/query.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,4 @@ suite('query', () => {
}
});
});
// TODO: interrupt
// TODO: query_progress
});
5 changes: 5 additions & 0 deletions bindings/test/utils/sleep.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export async function sleep(ms: number): Promise<void> {
return new Promise((resolve) => {
setTimeout(resolve, ms);
});
}