Skip to content

Commit

Permalink
chore: Expand contract tests to include persistent stores (#307)
Browse files Browse the repository at this point in the history
  • Loading branch information
keelerm84 authored Nov 7, 2024
1 parent ff64f36 commit 41d3abb
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .github/actions/ci/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ runs:
shell: bash
run: make start-contract-test-service-bg

- uses: launchdarkly/gh-actions/actions/contract-tests@contract-tests-v1.0.2
- uses: launchdarkly/gh-actions/actions/contract-tests@contract-tests-v1.2.0
if: ${{ !startsWith(inputs.ruby-version, 'jruby') }}
with:
test_service_port: 9000
enable_persistence_tests: true
token: ${{ inputs.token }}
7 changes: 7 additions & 0 deletions contract-tests/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,10 @@ gem 'json'
gem 'rubocop', '~> 1.37', group: 'development'
gem 'rubocop-performance', '~> 1.15', group: 'development'
gem 'thin', :platforms => :ruby

gem "redis", "~> 5.3"
gem "connection_pool", "~> 2.4"

gem "diplomat", "~> 2.6"

gem "aws-sdk-dynamodb", "~> 1.127"
38 changes: 38 additions & 0 deletions contract-tests/client_entity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,44 @@ def initialize(log, config)
opts[:base_uri] = polling[:baseUri] unless polling[:baseUri].nil?
opts[:payload_filter_key] = polling[:filter] unless polling[:filter].nil?
opts[:poll_interval] = polling[:pollIntervalMs] / 1_000.0 unless polling[:pollIntervalMs].nil?
else
opts[:use_ldd] = true
end

if config[:persistentDataStore]
store_config = {}
store_config[:prefix] = config[:persistentDataStore][:store][:prefix] if config[:persistentDataStore][:store][:prefix]

case config[:persistentDataStore][:cache][:mode]
when 'off'
store_config[:expiration] = 0
when 'infinite'
# NOTE: We don't actually support infinite cache mode, so we'll just set it to nil for now. This uses a default
# 15 second expiration time in the SDK, which is long enough to pass any test.
store_config[:expiration] = nil
when 'ttl'
store_config[:expiration] = config[:persistentDataStore][:cache][:ttl]
end

case config[:persistentDataStore][:store][:type]
when 'redis'
store_config[:redis_url] = config[:persistentDataStore][:store][:dsn]
store = LaunchDarkly::Integrations::Redis.new_feature_store(store_config)
opts[:feature_store] = store
when 'consul'
store_config[:url] = config[:persistentDataStore][:store][:url]
store = LaunchDarkly::Integrations::Consul.new_feature_store(store_config)
opts[:feature_store] = store
when 'dynamodb'
client = Aws::DynamoDB::Client.new(
region: 'us-east-1',
credentials: Aws::Credentials.new('dummy', 'dummy', 'dummy'),
endpoint: config[:persistentDataStore][:store][:dsn]
)
store_config[:existing_client] = client
store = LaunchDarkly::Integrations::DynamoDB.new_feature_store('sdk-contract-tests', store_config)
opts[:feature_store] = store
end
end

if config[:events]
Expand Down
3 changes: 3 additions & 0 deletions contract-tests/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@
'evaluation-hooks',
'omit-anonymous-contexts',
'client-prereq-events',
'persistent-data-store-consul',
'persistent-data-store-dynamodb',
'persistent-data-store-redis',
],
}.to_json
end
Expand Down

0 comments on commit 41d3abb

Please sign in to comment.