Skip to content
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

chore: Expand contract tests to include persistent stores #307

Merged
merged 4 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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