-
Notifications
You must be signed in to change notification settings - Fork 134
Test support for LibSQL using SQLite driver #957
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| /go.work.sum | ||
| /internal/cmd/riverbench/riverbench | ||
| /river | ||
| /riverdriver/riverdrivertest/example_libsql_test.libsql | ||
| /sqlite/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| package riverdrivertest_test | ||
|
|
||
| import ( | ||
| "context" | ||
| "database/sql" | ||
| "log/slog" | ||
|
|
||
| _ "github.com/tursodatabase/libsql-client-go/libsql" | ||
|
|
||
| "github.com/riverqueue/river" | ||
| "github.com/riverqueue/river/riverdriver/riversqlite" | ||
| "github.com/riverqueue/river/rivershared/riversharedtest" | ||
| "github.com/riverqueue/river/rivershared/util/slogutil" | ||
| "github.com/riverqueue/river/rivershared/util/testutil" | ||
| ) | ||
|
|
||
| // Example_libSQL demonstrates use of River's SQLite driver with libSQL (a | ||
| // SQLite fork). | ||
| func Example_libSQL() { //nolint:dupl | ||
| ctx := context.Background() | ||
|
|
||
| dbPool, err := sql.Open("libsql", "file:./example_libsql_test.libsql") | ||
| if err != nil { | ||
| panic(err) | ||
| } | ||
| dbPool.SetMaxOpenConns(1) | ||
| defer dbPool.Close() | ||
|
|
||
| driver := riversqlite.New(dbPool) | ||
|
|
||
| if err := migrateDB(ctx, driver); err != nil { | ||
| panic(err) | ||
| } | ||
|
|
||
| workers := river.NewWorkers() | ||
| river.AddWorker(workers, &SortWorker{}) | ||
|
|
||
| riverClient, err := river.NewClient(driver, &river.Config{ | ||
| Logger: slog.New(&slogutil.SlogMessageOnlyHandler{Level: slog.LevelWarn}), | ||
| Queues: map[string]river.QueueConfig{ | ||
| river.QueueDefault: {MaxWorkers: 100}, | ||
| }, | ||
| TestOnly: true, // suitable only for use in tests; remove for live environments | ||
| Workers: workers, | ||
| }) | ||
| if err != nil { | ||
| panic(err) | ||
| } | ||
|
|
||
| // Out of example scope, but used to wait until a job is worked. | ||
| subscribeChan, subscribeCancel := riverClient.Subscribe(river.EventKindJobCompleted) | ||
| defer subscribeCancel() | ||
|
|
||
| if err := riverClient.Start(ctx); err != nil { | ||
| panic(err) | ||
| } | ||
|
|
||
| _, err = riverClient.Insert(ctx, SortArgs{ | ||
| Strings: []string{ | ||
| "whale", "tiger", "bear", | ||
| }, | ||
| }, nil) | ||
| if err != nil { | ||
| panic(err) | ||
| } | ||
|
|
||
| // Wait for jobs to complete. Only needed for purposes of the example test. | ||
| riversharedtest.WaitOrTimeoutN(testutil.PanicTB(), subscribeChan, 1) | ||
|
|
||
| if err := riverClient.Stop(ctx); err != nil { | ||
| panic(err) | ||
| } | ||
|
|
||
| // Output: | ||
| // Sorted strings: [bear tiger whale] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Is it worth setting these up to use the same test logic to avoid having to add the
nolint:dupl? Or are there subtle differences between the two?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.
Yeah I struggle with these ones.
It is true that they are 95% the same. However, if you zoom out and look at what's happening, each body is basically one function call and a couple local variable declarations. There is definitely some duplication that falls out of anonymous functions injected into the function call and comments on them, so we could extract the function call into another function that could encapsulate the shared lines, but IMO this does have a non-zero effect to obfuscate (in that you now have to follow another layer of indirection to see what's happening) and reduce clarity.
I guess i'm not too against it, but it's definitely not a clear win like
duplwould suggest. More like a close to 50/50 tradeoff.Gonna leave it as is for now I think, and possibly reorient later if it comes up again.