Skip to content

Commit

Permalink
fix: Use correct flag version in evaluation events. (#166)
Browse files Browse the repository at this point in the history
There is an associated change to the sdk-test harness to ensure we don't
encounter this again.
  • Loading branch information
kinyoklion authored Oct 9, 2024
1 parent 4534fb8 commit 5d3e826
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 7 deletions.
2 changes: 1 addition & 1 deletion apps/flutter_client_contract_test_service/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ packages:
path: "../../packages/flutter_client_sdk"
relative: true
source: path
version: "4.6.0"
version: "4.7.0"
lints:
dependency: "direct dev"
description:
Expand Down
11 changes: 9 additions & 2 deletions packages/common/lib/src/ld_evaluation_result.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ final class LDEvaluationResult {
/// Incremented by LaunchDarkly each time the flag's state changes.
final int version;

/// The version of the flag. Changes when modifications are made to the flag.
final int? flagVersion;

/// True if a client SDK should track events for this flag.
final bool trackEvents;

Expand All @@ -24,15 +27,17 @@ final class LDEvaluationResult {

const LDEvaluationResult(
{required this.version,
this.flagVersion,
required this.detail,
this.trackEvents = false,
this.trackReason = false,
this.debugEventsUntilDate});

@override
String toString() {
return 'LDEvaluationResult{version: $version, trackEvents: $trackEvents, '
'trackReason: $trackReason, debugEventsUntilDate: $debugEventsUntilDate,'
return 'LDEvaluationResult{version: $version, flagVersion: $flagVersion,'
' trackEvents: $trackEvents, trackReason: $trackReason,'
' debugEventsUntilDate: $debugEventsUntilDate,'
' detail: $detail}';
}

Expand All @@ -41,6 +46,7 @@ final class LDEvaluationResult {
identical(this, other) ||
other is LDEvaluationResult &&
version == other.version &&
flagVersion == other.flagVersion &&
trackEvents == other.trackEvents &&
trackReason == other.trackReason &&
debugEventsUntilDate == other.debugEventsUntilDate &&
Expand All @@ -49,6 +55,7 @@ final class LDEvaluationResult {
@override
int get hashCode =>
version.hashCode ^
flagVersion.hashCode ^
trackEvents.hashCode ^
trackReason.hashCode ^
debugEventsUntilDate.hashCode ^
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import '../../launchdarkly_dart_common.dart';
final class LDEvaluationResultSerialization {
static LDEvaluationResult fromJson(Map<String, dynamic> json) {
final version = json['version'] as num;
final flagVersion = json['flagVersion'] as num?;
final trackEvents = (json['trackEvents'] ?? false) as bool;
final trackReason = (json['trackReason'] ?? false) as bool;
final debugEventsUntilDateRaw = json['debugEventsUntilDate'] as num?;
Expand All @@ -19,6 +20,7 @@ final class LDEvaluationResultSerialization {

return LDEvaluationResult(
version: version.toInt(),
flagVersion: flagVersion?.toInt(),
detail: LDEvaluationDetail(value, variationIndex, reason),
trackEvents: trackEvents,
trackReason: trackReason,
Expand Down
5 changes: 3 additions & 2 deletions packages/common/test/ld_evaluation_result_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,14 @@ void main() {

test('it produces the expected string', () {
final a = LDEvaluationResult(
version: 1,
version: 11,
flagVersion: 1,
detail: LDEvaluationDetail<LDValue>(
LDValue.ofString('toast'), null, LDEvaluationReason.targetMatch()));

expect(
a.toString(),
'LDEvaluationResult{version: 1, trackEvents: false, trackReason: false,'
'LDEvaluationResult{version: 11, flagVersion: 1, trackEvents: false, trackReason: false,'
' debugEventsUntilDate: null, detail: LDEvaluationDetail{value:'
' LDValue{_value: toast}, variationIndex: null, reason:'
' LDEvaluationReason{kind: TARGET_MATCH, ruleIndex: null,'
Expand Down
2 changes: 1 addition & 1 deletion packages/common_client/lib/src/ld_common_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ final class LDCommonClient {
? DateTime.fromMillisecondsSinceEpoch(
evalResult!.flag!.debugEventsUntilDate!)
: null,
version: evalResult?.version));
version: evalResult?.flag?.flagVersion ?? evalResult?.version));

return detail;
}
Expand Down
3 changes: 2 additions & 1 deletion packages/common_client/test/ld_dart_client_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ final class TestDataSource implements DataSource {
_eventController.sink.add(DataEvent(
'put',
'{"flagA":{'
'"version":1,'
'"version":11,'
'"flagVersion":1,'
'"value":"datasource",'
'"variation":0,'
'"reason":{"kind":"OFF"}'
Expand Down

0 comments on commit 5d3e826

Please sign in to comment.