Skip to content

Commit

Permalink
increase timeout for libsql tests (#3855)
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-smart authored Oct 29, 2024
1 parent 3a6d757 commit 54284ea
Show file tree
Hide file tree
Showing 2 changed files with 143 additions and 145 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jobs:
strategy:
fail-fast: false
matrix:
shard: [1/3, 2/3, 3/3]
shard: [1/4, 2/4, 3/4, 4/4]
# runtime: [Node, Bun] # TODO: Re-enable bun test suite after https://github.com/oven-sh/bun/issues/4145 is resolved
runtime: [Node]
steps:
Expand Down
286 changes: 142 additions & 144 deletions packages/sql-libsql/test/Resolver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,160 +15,158 @@ const seededClient = Effect.gen(function*(_) {
return sql
})

describe("Resolver", () => {
layer(LibsqlContainer.ClientLive)((it) => {
describe("ordered", () => {
it.scoped("insert", () =>
Effect.gen(function*(_) {
const batches: Array<Array<string>> = []
const sql = yield* _(seededClient)
const Insert = yield* _(SqlResolver.ordered("Insert", {
Request: Schema.String,
Result: Schema.Struct({ id: Schema.Number, name: Schema.String }),
execute: (names) => {
batches.push(names)
return sql`INSERT INTO test ${sql.insert(names.map((name) => ({ name })))} RETURNING *`
}
}))
assert.deepStrictEqual(
yield* _(Effect.all({
one: Insert.execute("one"),
two: Insert.execute("two")
}, { batching: true })),
{
one: { id: 101, name: "one" },
two: { id: 102, name: "two" }
}
)
assert.deepStrictEqual(batches, [["one", "two"]])
layer(LibsqlContainer.ClientLive, { timeout: "30 seconds" })("Resolver", (it) => {
describe("ordered", () => {
it.scoped("insert", () =>
Effect.gen(function*(_) {
const batches: Array<Array<string>> = []
const sql = yield* _(seededClient)
const Insert = yield* _(SqlResolver.ordered("Insert", {
Request: Schema.String,
Result: Schema.Struct({ id: Schema.Number, name: Schema.String }),
execute: (names) => {
batches.push(names)
return sql`INSERT INTO test ${sql.insert(names.map((name) => ({ name })))} RETURNING *`
}
}))
assert.deepStrictEqual(
yield* _(Effect.all({
one: Insert.execute("one"),
two: Insert.execute("two")
}, { batching: true })),
{
one: { id: 101, name: "one" },
two: { id: 102, name: "two" }
}
)
assert.deepStrictEqual(batches, [["one", "two"]])
}))

it.scoped("result length mismatch", () =>
Effect.gen(function*(_) {
const batches: Array<Array<number>> = []
const sql = yield* _(seededClient)
const Select = yield* _(SqlResolver.ordered("Select", {
Request: Schema.Number,
Result: Schema.Struct({ id: Schema.Number, name: Schema.String }),
execute: (ids) => {
batches.push(ids)
return sql`SELECT * FROM test WHERE id IN ${sql.in(ids)}`
}
}))
const error = yield* _(
Effect.all([
Select.execute(1),
Select.execute(2),
Select.execute(3),
Select.execute(101)
], { batching: true }),
Effect.flip
)
assert(error instanceof SqlError.ResultLengthMismatch)
assert.strictEqual(error.actual, 3)
assert.strictEqual(error.expected, 4)
assert.deepStrictEqual(batches, [[1, 2, 3, 101]])
it.scoped("result length mismatch", () =>
Effect.gen(function*(_) {
const batches: Array<Array<number>> = []
const sql = yield* _(seededClient)
const Select = yield* _(SqlResolver.ordered("Select", {
Request: Schema.Number,
Result: Schema.Struct({ id: Schema.Number, name: Schema.String }),
execute: (ids) => {
batches.push(ids)
return sql`SELECT * FROM test WHERE id IN ${sql.in(ids)}`
}
}))
})
const error = yield* _(
Effect.all([
Select.execute(1),
Select.execute(2),
Select.execute(3),
Select.execute(101)
], { batching: true }),
Effect.flip
)
assert(error instanceof SqlError.ResultLengthMismatch)
assert.strictEqual(error.actual, 3)
assert.strictEqual(error.expected, 4)
assert.deepStrictEqual(batches, [[1, 2, 3, 101]])
}))
})

describe("grouped", () => {
it.scoped("find by name", () =>
Effect.gen(function*(_) {
const sql = yield* _(seededClient)
const FindByName = yield* _(SqlResolver.grouped("FindByName", {
Request: Schema.String,
RequestGroupKey: (name) => name,
Result: Schema.Struct({ id: Schema.Number, name: Schema.String }),
ResultGroupKey: (result) => result.name,
execute: (names) => sql`SELECT * FROM test WHERE name IN ${sql.in(names)}`
}))
yield* _(sql`INSERT INTO test ${sql.insert({ name: "name1" })}`)
assert.deepStrictEqual(
yield* _(Effect.all({
one: FindByName.execute("name1"),
two: FindByName.execute("name2"),
three: FindByName.execute("name0")
}, { batching: true })),
{
one: [{ id: 1, name: "name1" }, { id: 101, name: "name1" }],
two: [{ id: 2, name: "name2" }],
three: []
}
)
describe("grouped", () => {
it.scoped("find by name", () =>
Effect.gen(function*(_) {
const sql = yield* _(seededClient)
const FindByName = yield* _(SqlResolver.grouped("FindByName", {
Request: Schema.String,
RequestGroupKey: (name) => name,
Result: Schema.Struct({ id: Schema.Number, name: Schema.String }),
ResultGroupKey: (result) => result.name,
execute: (names) => sql`SELECT * FROM test WHERE name IN ${sql.in(names)}`
}))
yield* _(sql`INSERT INTO test ${sql.insert({ name: "name1" })}`)
assert.deepStrictEqual(
yield* _(Effect.all({
one: FindByName.execute("name1"),
two: FindByName.execute("name2"),
three: FindByName.execute("name0")
}, { batching: true })),
{
one: [{ id: 1, name: "name1" }, { id: 101, name: "name1" }],
two: [{ id: 2, name: "name2" }],
three: []
}
)
}))

it.scoped("using raw rows", () =>
Effect.gen(function*(_) {
const sql = yield* _(seededClient)
const FindByName = yield* _(SqlResolver.grouped("FindByName", {
Request: Schema.String,
RequestGroupKey: (name) => name,
Result: Schema.Struct({ id: Schema.Number, name: Schema.String }),
ResultGroupKey: (_, result: any) => result.name,
execute: (names) => sql`SELECT * FROM test WHERE name IN ${sql.in(names)}`
}))
yield* _(sql`INSERT INTO test ${sql.insert({ name: "name1" })}`)
assert.deepStrictEqual(
yield* _(Effect.all({
one: FindByName.execute("name1"),
two: FindByName.execute("name2"),
three: FindByName.execute("name0")
}, { batching: true })),
{
one: [{ id: 1, name: "name1" }, { id: 101, name: "name1" }],
two: [{ id: 2, name: "name2" }],
three: []
}
)
it.scoped("using raw rows", () =>
Effect.gen(function*(_) {
const sql = yield* _(seededClient)
const FindByName = yield* _(SqlResolver.grouped("FindByName", {
Request: Schema.String,
RequestGroupKey: (name) => name,
Result: Schema.Struct({ id: Schema.Number, name: Schema.String }),
ResultGroupKey: (_, result: any) => result.name,
execute: (names) => sql`SELECT * FROM test WHERE name IN ${sql.in(names)}`
}))
})
yield* _(sql`INSERT INTO test ${sql.insert({ name: "name1" })}`)
assert.deepStrictEqual(
yield* _(Effect.all({
one: FindByName.execute("name1"),
two: FindByName.execute("name2"),
three: FindByName.execute("name0")
}, { batching: true })),
{
one: [{ id: 1, name: "name1" }, { id: 101, name: "name1" }],
two: [{ id: 2, name: "name2" }],
three: []
}
)
}))
})

describe("findById", () => {
it.scoped("find by id", () =>
Effect.gen(function*(_) {
const sql = yield* _(seededClient)
const FindById = yield* _(SqlResolver.findById("FindById", {
Id: Schema.Number,
Result: Schema.Struct({ id: Schema.Number, name: Schema.String }),
ResultId: (result) => result.id,
execute: (ids) => sql`SELECT * FROM test WHERE id IN ${sql.in(ids)}`
}))
assert.deepStrictEqual(
yield* _(Effect.all({
one: FindById.execute(1),
two: FindById.execute(2),
three: FindById.execute(101)
}, { batching: true })),
{
one: Option.some({ id: 1, name: "name1" }),
two: Option.some({ id: 2, name: "name2" }),
three: Option.none()
}
)
describe("findById", () => {
it.scoped("find by id", () =>
Effect.gen(function*(_) {
const sql = yield* _(seededClient)
const FindById = yield* _(SqlResolver.findById("FindById", {
Id: Schema.Number,
Result: Schema.Struct({ id: Schema.Number, name: Schema.String }),
ResultId: (result) => result.id,
execute: (ids) => sql`SELECT * FROM test WHERE id IN ${sql.in(ids)}`
}))
assert.deepStrictEqual(
yield* _(Effect.all({
one: FindById.execute(1),
two: FindById.execute(2),
three: FindById.execute(101)
}, { batching: true })),
{
one: Option.some({ id: 1, name: "name1" }),
two: Option.some({ id: 2, name: "name2" }),
three: Option.none()
}
)
}))

it.scoped("using raw rows", () =>
Effect.gen(function*(_) {
const sql = yield* _(seededClient)
const FindById = yield* _(SqlResolver.findById("FindById", {
Id: Schema.Number,
Result: Schema.Struct({ id: Schema.Number, name: Schema.String }),
ResultId: (_, result: any) => result.id,
execute: (ids) => sql`SELECT * FROM test WHERE id IN ${sql.in(ids)}`
}))
assert.deepStrictEqual(
yield* _(Effect.all({
one: FindById.execute(1),
two: FindById.execute(2),
three: FindById.execute(101)
}, { batching: true })),
{
one: Option.some({ id: 1, name: "name1" }),
two: Option.some({ id: 2, name: "name2" }),
three: Option.none()
}
)
it.scoped("using raw rows", () =>
Effect.gen(function*(_) {
const sql = yield* _(seededClient)
const FindById = yield* _(SqlResolver.findById("FindById", {
Id: Schema.Number,
Result: Schema.Struct({ id: Schema.Number, name: Schema.String }),
ResultId: (_, result: any) => result.id,
execute: (ids) => sql`SELECT * FROM test WHERE id IN ${sql.in(ids)}`
}))
})
assert.deepStrictEqual(
yield* _(Effect.all({
one: FindById.execute(1),
two: FindById.execute(2),
three: FindById.execute(101)
}, { batching: true })),
{
one: Option.some({ id: 1, name: "name1" }),
two: Option.some({ id: 2, name: "name2" }),
three: Option.none()
}
)
}))
})
})

0 comments on commit 54284ea

Please sign in to comment.