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

[pull] main from oven-sh:main #91

Merged
merged 3 commits into from
Jan 8, 2025
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
14 changes: 14 additions & 0 deletions docs/api/ffi.md
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,20 @@ setTimeout(() => {

When you're done with a JSCallback, you should call `close()` to free the memory.

### Experimental thread-safe callbacks
`JSCallback` has experimental support for thread-safe callbacks. This will be needed if you pass a callback function into a different thread from it's instantiation context. You can enable it with the optional `threadsafe` option flag.
```ts
const searchIterator = new JSCallback(
(ptr, length) => /hello/.test(new CString(ptr, length)),
{
returns: "bool",
args: ["ptr", "usize"],
threadsafe: true, // Optional. Defaults to `false`
},
);
```
Be aware that there are still cases where this does not 100% work.

{% callout %}

**⚡️ Performance tip** — For a slight performance boost, directly pass `JSCallback.prototype.ptr` instead of the `JSCallback` object:
Expand Down
14 changes: 11 additions & 3 deletions scripts/runner.node.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ async function runTests() {
if (!failedResults.length) {
for (const testPath of tests) {
const title = relative(cwd, join(testsPath, testPath)).replace(/\\/g, "/");
if (title.startsWith("test/js/node/test/parallel/")) {
if (isNodeParallelTest(testPath)) {
await runTest(title, async () => {
const { ok, error, stdout } = await spawnBun(execPath, {
cwd: cwd,
Expand Down Expand Up @@ -850,12 +850,20 @@ function isJavaScriptTest(path) {
return isJavaScript(path) && /\.test|spec\./.test(basename(path));
}

/**
* @param {string} testPath
* @returns {boolean}
*/
function isNodeParallelTest(testPath) {
return testPath.replaceAll(sep, "/").includes("js/node/test/parallel/")
}

/**
* @param {string} path
* @returns {boolean}
*/
function isTest(path) {
if (path.replaceAll(sep, "/").startsWith("js/node/test/parallel/") && targetDoesRunNodeTests()) return true;
if (isNodeParallelTest(path) && targetDoesRunNodeTests()) return true;
if (path.replaceAll(sep, "/").startsWith("js/node/cluster/test-") && path.endsWith(".ts")) return true;
return isTestStrict(path);
}
Expand Down Expand Up @@ -1035,7 +1043,7 @@ function getRelevantTests(cwd) {
const filteredTests = [];

if (options["node-tests"]) {
tests = tests.filter(testPath => testPath.includes("js/node/test/parallel/"));
tests = tests.filter(isNodeParallelTest);
}

const isMatch = (testPath, filter) => {
Expand Down
3 changes: 2 additions & 1 deletion test/js/sql/sql.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { $ } from "bun";
import { bunExe, isCI, withoutAggressiveGC } from "harness";
import path from "path";

if (!isCI) {
const hasPsql = Bun.which("psql");
if (!isCI && hasPsql) {
require("./bootstrap.js");

// macOS location: /opt/homebrew/var/postgresql@14/pg_hba.conf
Expand Down
32 changes: 17 additions & 15 deletions test/js/sql/tls-sql.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,22 @@ import { sql as SQL } from "bun";

const TLS_POSTGRES_DATABASE_URL = getSecret("TLS_POSTGRES_DATABASE_URL");

test("tls (explicit)", async () => {
const sql = new SQL({
url: TLS_POSTGRES_DATABASE_URL!,
tls: true,
adapter: "postgresql",
});
if (TLS_POSTGRES_DATABASE_URL) {
test("tls (explicit)", async () => {
const sql = new SQL({
url: TLS_POSTGRES_DATABASE_URL!,
tls: true,
adapter: "postgresql",
});

const [{ one, two }] = await sql`SELECT 1 as one, '2' as two`;
expect(one).toBe(1);
expect(two).toBe("2");
});
const [{ one, two }] = await sql`SELECT 1 as one, '2' as two`;
expect(one).toBe(1);
expect(two).toBe("2");
});

test("tls (implicit)", async () => {
const [{ one, two }] = await SQL`SELECT 1 as one, '2' as two`;
expect(one).toBe(1);
expect(two).toBe("2");
});
test("tls (implicit)", async () => {
const [{ one, two }] = await SQL`SELECT 1 as one, '2' as two`;
expect(one).toBe(1);
expect(two).toBe("2");
});
}
Loading