Skip to content

Commit

Permalink
Mitigate problems using an in-memory database
Browse files Browse the repository at this point in the history
The tests began to fail when re-enabling transactions as they're incompatible with in-memory SQLite databases. It should be possible to use `file::memory:?cache=shared` rather than `:memory:`, but this also doesn't entirely. To avoid spending more time on this problem, this commit uses temporary file-based databases in the tests.

Refs #1973, 3acf814, tursodatabase/libsql-client-ts#229, https://www.sqlite.org/inmemorydb.html
  • Loading branch information
thewilkybarkid committed Oct 9, 2024
1 parent 3acf814 commit f69e82c
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions test/LibsqlEventStore.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { FileSystem } from '@effect/platform'
import { NodeFileSystem } from '@effect/platform-node'
import { LibsqlClient } from '@effect/sql-libsql'
import { it } from '@fast-check/jest'
import { describe, expect } from '@jest/globals'
import { Array, Config, Effect, Equal, TestContext } from 'effect'
import { Array, Config, Effect, Equal, Layer, TestContext } from 'effect'
import * as EventStore from '../src/EventStore.js'
import * as _ from '../src/LibsqlEventStore.js'
import { Uuid } from '../src/types/index.js'
Expand All @@ -19,7 +21,7 @@ it.prop([fc.uuid()])('starts empty', resourceId =>
expect(all).toStrictEqual([])
}).pipe(
Effect.provideService(Uuid.GenerateUuid, Effect.sync(shouldNotBeCalled)),
Effect.provide(LibsqlClient.layer({ url: Config.succeed(':memory:') })),
Effect.provide(TestLibsqlClient),
Effect.provide(TestContext.TestContext),
Effect.runPromise,
),
Expand All @@ -38,7 +40,7 @@ it.prop([fc.uuid(), fc.nonEmptyArray(fc.feedbackEvent())])('creates a new resour
expect(all).toStrictEqual(Array.map(events, (event, i) => ({ event, resourceId, version: i + 1 })))
}).pipe(
Effect.provideServiceEffect(Uuid.GenerateUuid, Uuid.make),
Effect.provide(LibsqlClient.layer({ url: Config.succeed(':memory:') })),
Effect.provide(TestLibsqlClient),
Effect.provide(TestContext.TestContext),
Effect.runPromise,
),
Expand All @@ -64,7 +66,7 @@ describe('when the last known version is up to date', () => {
])
}).pipe(
Effect.provideServiceEffect(Uuid.GenerateUuid, Uuid.make),
Effect.provide(LibsqlClient.layer({ url: Config.succeed(':memory:') })),
Effect.provide(TestLibsqlClient),
Effect.provide(TestContext.TestContext),
Effect.runPromise,
),
Expand Down Expand Up @@ -101,7 +103,7 @@ describe('when the last known version is out of date', () => {
])
}).pipe(
Effect.provideServiceEffect(Uuid.GenerateUuid, Uuid.make),
Effect.provide(LibsqlClient.layer({ url: Config.succeed(':memory:') })),
Effect.provide(TestLibsqlClient),
Effect.provide(TestContext.TestContext),
Effect.runPromise,
),
Expand Down Expand Up @@ -138,8 +140,17 @@ it.prop([
])
}).pipe(
Effect.provideServiceEffect(Uuid.GenerateUuid, Uuid.make),
Effect.provide(LibsqlClient.layer({ url: Config.succeed(':memory:') })),
Effect.provide(TestLibsqlClient),
Effect.provide(TestContext.TestContext),
Effect.runPromise,
),
)

const TestLibsqlClient = Layer.unwrapScoped(
Effect.gen(function* () {
const fs = yield* FileSystem.FileSystem
const file = yield* fs.makeTempFileScoped()

return LibsqlClient.layer({ url: Config.succeed(`file:${file}`) })
}),
).pipe(Layer.provide(NodeFileSystem.layer))

0 comments on commit f69e82c

Please sign in to comment.