diff --git a/lib/ldclient-rb/impl/integrations/consul_impl.rb b/lib/ldclient-rb/impl/integrations/consul_impl.rb index 143868ed..d3e8a1a2 100644 --- a/lib/ldclient-rb/impl/integrations/consul_impl.rb +++ b/lib/ldclient-rb/impl/integrations/consul_impl.rb @@ -69,8 +69,7 @@ def get_internal(kind, key) def get_all_internal(kind) items_out = {} prefix = kind_key(kind) - results = Diplomat::Kv.get(prefix, { recurse: true }, :return) - (results == "" ? [] : results).each do |result| + Diplomat::Kv.get_all(prefix, {}, :return).each do |result| value = result[:value] next if value.nil? db_key = result[:key].to_s diff --git a/spec/feature_store_spec_base.rb b/spec/feature_store_spec_base.rb index 7ef7d3c4..bfd0d333 100644 --- a/spec/feature_store_spec_base.rb +++ b/spec/feature_store_spec_base.rb @@ -264,6 +264,34 @@ def new_version_plus(f, delta_version, attrs = {}) end end end + + it "can read all items when a kind holds a single item" do + # A store must treat a collection of one as a collection. Some database clients + # return a single matching row on its own, rather than in a list. + ensure_stop(store_tester.create_feature_store) do |store1| + store1.init({ $things_kind => { $key1.to_sym => $thing1 } }) + + # A second instance reads through to the database instead of its own cache. + ensure_stop(store_tester.create_feature_store) do |store2| + expect(store2.all($things_kind)).to eq({ $key1.to_sym => $thing1 }) + end + end + end + + it "can read all items when the single item is a tombstone with no key" do + # This is the single-item case where the one item is also a deleted item with no + # key of its own, as happens for a one-flag project or after every flag is deleted. + ensure_stop(store_tester.create_feature_store) do |store1| + store1.init({ $things_kind => {} }) + store_tester.write_raw_item($things_kind, "deleted-thing", { version: 99, deleted: true }) + + # A second instance reads through to the database instead of its own cache. + ensure_stop(store_tester.create_feature_store) do |store2| + expect(store2.all($things_kind)).to eq({}) + expect(store2.get($things_kind, "deleted-thing")).to be_nil + end + end + end end end