-
Notifications
You must be signed in to change notification settings - Fork 105
In-memory interface to make testing easier #5225
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
base: main
Are you sure you want to change the base?
Conversation
|
Someone is attempting to deploy a commit to the Rocicorp Team on Vercel. A member of the Team first needs to authorize it. |
| "types": "./out/zero/src/sqlite.d.ts", | ||
| "default": "./out/zero/src/sqlite.js" | ||
| }, | ||
| "./test-helpers": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unsure where this should be exported from, left this as a placeholder
packages/zero/src/test-helpers.ts
Outdated
| import {QueryDelegateImpl} from '../../zql/src/query/test/query-delegate.ts'; | ||
| import {MemorySource} from '../../zql/src/ivm/memory-source.ts'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this change is not desired, would be nice to export these dependencies at least.
|
I'm really sorry about the slow reply here - we need to get better at monitoring the PRs for user submissions. Can you say more about what the intent here is? What kind of tests are you trying to write? |
|
The intent is to make tests of queries as fast as possible and not require any docker setup. In my case, I have non-trivial authorization rules that I need to test (e.g. a record can be returned if a user has a grant to it or the user belongs to a group that has a grant to it). I recognize it's possible to test this end-to-end, but I'd like to have most of my tests be unit tests if possible. I actually originally looked into using SQLite / ZQLite to run these, but stumbled upon the MemorySource and test QueryDelegate after getting pointed in the right direction. Using an in-memory instance of these means I don't even need to copy around SQLite files in test setups.
|
|
Sorry, I didn't see this. Feel free to add me as a reviewer next time! For others on the team, this is different from our existing The key difference is what layer of the stack is being testing: TestZero with kvStore: 'mem' still runs the full Zero client stack:
MemoryZeroImpl bypasses all that and talks directly to the ZQL query engine:
My main piece of feedback would be that The other would be that we want to keep total code surface area down so I'd need to look into what existing test helpers we can replace with this -- given your helper is more complete than the ones we have today. Ideally we can update zql-integration-tests/helpers/runner.ts to use this new utility to reduce duplication. |
I think this is possible today just with |
Gave another pass at getting this running with
Obviously providing a valid URL corresponding to an instance of zero-cache would work, but that kind of defeats the point here. |
|
If you pass |
|
Passing |
33dd7b7 to
ce1df15
Compare
|
@tantaman I took a pass at using |
dc2d190 to
d131e09
Compare
Adds an interface and impl for running mutations/queries/transactions backed only by memory storage. The idea is to use this for testing, specifically for permissions enforced via synced queries. Based on discussion here: https://discord.com/channels/830183651022471199/830183651022471202/1442950450503483627
Example usage: