Add 'Fail' mode when no shard selected#859
Open
nothrow wants to merge 2 commits intopostgresml:mainfrom
Open
Conversation
Collaborator
|
I am fine with the change but I think there should be tests for this. We are already testing the default_shard parameter here, adding one test case for |
|
@nothrow @magec I've implemented a test case for this: diff --git a/tests/ruby/sharding_spec.rb b/tests/ruby/sharding_spec.rb
index 746627d..456997c 100644
--- a/tests/ruby/sharding_spec.rb
+++ b/tests/ruby/sharding_spec.rb
@@ -129,6 +129,26 @@ describe "Sharding" do
end
end
+ context "when no_shard_specified_behavior config is set to fail" do
+ let(:no_shard_specified_behavior) { "fail" }
+
+ context "with no shard comment" do
+ it "fails and doesn't send the query" do
+ conn = PG.connect(processes.pgcat.connection_string("sharded_db", "sharding_user"))
+ expect { conn.async_exec("SELECT 1 + 2").to_a }.to raise_error(PG::SystemError).with_message(/NoShardSelected/)
+ end
+ end
+
+ context "with a shard comment" do
+ it "honors the comment" do
+ conn = PG.connect(processes.pgcat.connection_string("sharded_db", "sharding_user"))
+ 25.times { conn.async_exec("#{comment_to_use} SELECT 1 + 2") }
+
+ expect(processes.all_databases.map(&:count_select_1_plus_2)).to eq([0, 25, 0])
+ end
+ end
+ end
+
context "when no_shard_specified_behavior config is set to random_healthy" do
let(:no_shard_specified_behavior) { "random_healthy" }Hopefully this can be merged soon :) |
Collaborator
|
I' fine with merging this. What do you think @drdrsh ? |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Implementation for feature request & proposed solution in #858.
Adds new option for
default_shard.