Skip to content

Commit 41d3abb

Browse files
authored
chore: Expand contract tests to include persistent stores (#307)
1 parent ff64f36 commit 41d3abb

File tree

4 files changed

+50
-1
lines changed

4 files changed

+50
-1
lines changed

.github/actions/ci/action.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,9 @@ runs:
4343
shell: bash
4444
run: make start-contract-test-service-bg
4545

46-
- uses: launchdarkly/gh-actions/actions/contract-tests@contract-tests-v1.0.2
46+
- uses: launchdarkly/gh-actions/actions/contract-tests@contract-tests-v1.2.0
4747
if: ${{ !startsWith(inputs.ruby-version, 'jruby') }}
4848
with:
4949
test_service_port: 9000
50+
enable_persistence_tests: true
5051
token: ${{ inputs.token }}

contract-tests/Gemfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,10 @@ gem 'json'
1111
gem 'rubocop', '~> 1.37', group: 'development'
1212
gem 'rubocop-performance', '~> 1.15', group: 'development'
1313
gem 'thin', :platforms => :ruby
14+
15+
gem "redis", "~> 5.3"
16+
gem "connection_pool", "~> 2.4"
17+
18+
gem "diplomat", "~> 2.6"
19+
20+
gem "aws-sdk-dynamodb", "~> 1.127"

contract-tests/client_entity.rb

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,44 @@ def initialize(log, config)
2525
opts[:base_uri] = polling[:baseUri] unless polling[:baseUri].nil?
2626
opts[:payload_filter_key] = polling[:filter] unless polling[:filter].nil?
2727
opts[:poll_interval] = polling[:pollIntervalMs] / 1_000.0 unless polling[:pollIntervalMs].nil?
28+
else
29+
opts[:use_ldd] = true
30+
end
31+
32+
if config[:persistentDataStore]
33+
store_config = {}
34+
store_config[:prefix] = config[:persistentDataStore][:store][:prefix] if config[:persistentDataStore][:store][:prefix]
35+
36+
case config[:persistentDataStore][:cache][:mode]
37+
when 'off'
38+
store_config[:expiration] = 0
39+
when 'infinite'
40+
# NOTE: We don't actually support infinite cache mode, so we'll just set it to nil for now. This uses a default
41+
# 15 second expiration time in the SDK, which is long enough to pass any test.
42+
store_config[:expiration] = nil
43+
when 'ttl'
44+
store_config[:expiration] = config[:persistentDataStore][:cache][:ttl]
45+
end
46+
47+
case config[:persistentDataStore][:store][:type]
48+
when 'redis'
49+
store_config[:redis_url] = config[:persistentDataStore][:store][:dsn]
50+
store = LaunchDarkly::Integrations::Redis.new_feature_store(store_config)
51+
opts[:feature_store] = store
52+
when 'consul'
53+
store_config[:url] = config[:persistentDataStore][:store][:url]
54+
store = LaunchDarkly::Integrations::Consul.new_feature_store(store_config)
55+
opts[:feature_store] = store
56+
when 'dynamodb'
57+
client = Aws::DynamoDB::Client.new(
58+
region: 'us-east-1',
59+
credentials: Aws::Credentials.new('dummy', 'dummy', 'dummy'),
60+
endpoint: config[:persistentDataStore][:store][:dsn]
61+
)
62+
store_config[:existing_client] = client
63+
store = LaunchDarkly::Integrations::DynamoDB.new_feature_store('sdk-contract-tests', store_config)
64+
opts[:feature_store] = store
65+
end
2866
end
2967

3068
if config[:events]

contract-tests/service.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@
4545
'evaluation-hooks',
4646
'omit-anonymous-contexts',
4747
'client-prereq-events',
48+
'persistent-data-store-consul',
49+
'persistent-data-store-dynamodb',
50+
'persistent-data-store-redis',
4851
],
4952
}.to_json
5053
end

0 commit comments

Comments
 (0)