Skip to content

feat: Add support for test datasource#157

Merged
keelerm84 merged 5 commits intofeat/3.xfrom
mk/sdk-1886/test-datasource
Mar 3, 2026
Merged

feat: Add support for test datasource#157
keelerm84 merged 5 commits intofeat/3.xfrom
mk/sdk-1886/test-datasource

Conversation

@keelerm84
Copy link
Member

@keelerm84 keelerm84 commented Mar 2, 2026

Note

Medium Risk
Adds a new public TestData data source and upgrades the evaluation crate, which can affect how flags/segments are versioned and propagated to client stores; overall scope is mostly additive and test-focused but touches core data-source wiring.

Overview
Introduces a new TestData data source that can be passed to ConfigBuilder::data_source to inject and dynamically update flags/segments without any LaunchDarkly network connection, including automatic per-key version increments and propagation to all subscribed client stores.

Exports TestData (and evaluation builders like FlagBuilder/RuleBuilder) from lib.rs, bumps launchdarkly-server-sdk-evaluation to 2.1.0, and refactors client.rs tests to use TestData instead of manually upserting into the store (updating expected flag versions accordingly).

Written by Cursor Bugbot for commit e00a3b9. This will update automatically on new commits. Configure here.

@keelerm84
Copy link
Member Author

Pending release of launchdarkly/rust-server-sdk-evaluation#33

@keelerm84 keelerm84 force-pushed the mk/sdk-1886/test-datasource branch from 0d05548 to fccb5c4 Compare March 2, 2026 19:23
@keelerm84 keelerm84 marked this pull request as ready for review March 2, 2026 19:23
@keelerm84 keelerm84 requested a review from a team as a code owner March 2, 2026 19:23
let inner = self.inner.lock();
match inner.flag_origins.get(key) {
Some(FlagOrigin::Builder(builder)) => builder.clone(),
Some(FlagOrigin::Preconfigured) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would prefer fallthrough or hydration over this.

/// Use this when you need to set a flag with a configuration that cannot be expressed through
/// [`FlagBuilder`](crate::FlagBuilder). The flag version is automatically managed.
///
/// After calling this, you cannot use [`TestData::flag`] to get a builder for this flag key.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment will need updated if/when we update the behavior.


// Spawn a task to unregister the store on shutdown
let inner_ref = self.inner.clone();
let store_ptr = Arc::as_ptr(&data_store) as *const () as usize;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feels excessively complex and gross.

}

#[tokio::test]
async fn use_preconfigured_segment_propagates() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a test to ensure preconfigured flags increment version.

Add a test equivalent to update_increments_version_each_call which validates the same behavior but using .flag

keelerm84 and others added 3 commits March 3, 2026 14:29
…ured flags

Instead of panicking when flag() is called on a key set via
use_preconfigured_flag, fall through and return a new default
FlagBuilder. Hydrating a builder from a Flag isn't feasible because
FlagBuilder cannot represent all flag fields (prerequisites, migration
settings, client visibility, etc.) and would silently lose data.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace the raw pointer cast chain (Arc::as_ptr as *const () as usize)
with Arc::ptr_eq for comparing store instances during shutdown cleanup.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ilder

Add use_preconfigured_flag_increments_version_each_call and
flag_builder_increments_version_each_call to verify version auto-management
works correctly across repeated updates for both code paths.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@keelerm84 keelerm84 merged commit d4b73ec into feat/3.x Mar 3, 2026
21 of 22 checks passed
@keelerm84 keelerm84 deleted the mk/sdk-1886/test-datasource branch March 3, 2026 20:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants