Skip to content
Open
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
37 changes: 37 additions & 0 deletions packages/libsql-client/src/__tests__/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,3 +232,40 @@ describe("expandConfig - parsing of valid arguments", () => {
});
}
});

describe("expandConfig - concurrency", () => {
const cases = [
{
name: "default",
config: { url: "file://local.db" },
concurrency: 20,
},
{
name: "explicit limit",
config: { url: "file://local.db", concurrency: 42 },
concurrency: 42,
},
{
name: "zero disables the limit",
config: { url: "file://local.db", concurrency: 0 },
concurrency: 0,
},
{
name: "negative clamps to zero",
config: { url: "file://local.db", concurrency: -5 },
concurrency: 0,
},
{
name: "in-memory zero disables the limit",
config: { url: ":memory:", concurrency: 0 },
concurrency: 0,
},
];
for (const { name, config, concurrency } of cases) {
test(name, () => {
expect(expandConfig(config, false).concurrency).toEqual(
concurrency,
);
});
}
});
6 changes: 5 additions & 1 deletion packages/libsql-client/src/sqlite3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,12 @@ export function _createClient(config: ExpandedConfig): Client {
// second connection would be a second, empty database rather than another
// way into the same one. Each connection to an embedded replica carries
// its own sync state. Both are therefore single-connection databases.
// A concurrency of 0 means no limit, matching the remote clients, whose
// promise-limit semaphore treats a falsy limit as pass-through.
const maxConnections =
isInMemory || config.syncUrl ? 1 : Math.max(1, config.concurrency);
isInMemory || config.syncUrl
? 1
: Math.max(1, config.concurrency || Infinity);

const options = {
authToken: config.authToken,
Expand Down
2 changes: 1 addition & 1 deletion packages/libsql-core/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export function expandConfig(

let { url, authToken, tls, intMode, concurrency } = config;
// fill simple defaults right here
concurrency = Math.max(0, concurrency || 20);
concurrency = Math.max(0, concurrency ?? 20);
intMode ??= "number";

let connectionQueryParams: string[] = []; // recognized query parameters which we sanitize through white list of valid key-value pairs
Expand Down