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

fix: Change notification consistency. #473

Merged
merged 2 commits into from
Jan 28, 2025
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
4 changes: 2 additions & 2 deletions .github/actions/install-boost/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ runs:
id: boost-download
shell: bash
run: |
choco install boost-msvc-14.3 --version 1.81.0 -y --no-progress
echo "BOOST_ROOT=C:\local\boost_1_81_0" >> $GITHUB_OUTPUT
choco install boost-msvc-14.3 --version 1.87.0 -y --no-progress
echo "BOOST_ROOT=C:\local\boost_1_87_0" >> $GITHUB_OUTPUT

- name: Install boost using homebrew
id: brew-action
Expand Down
2 changes: 1 addition & 1 deletion libs/client-sdk/src/flag_manager/flag_updater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ void FlagUpdater::Upsert(Context const& context,
return;
}

flag_store_.Upsert(key, descriptor);
if (HasListeners()) {
// Existed and updated.
if (existing && descriptor.item) {
Expand All @@ -112,7 +113,6 @@ void FlagUpdater::Upsert(Context const& context,
// Do nothing.
}
}
flag_store_.Upsert(key, descriptor);
}

bool FlagUpdater::HasListeners() const {
Expand Down
31 changes: 28 additions & 3 deletions libs/client-sdk/tests/flag_updater_test.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <gtest/gtest.h>

Check notice on line 1 in libs/client-sdk/tests/flag_updater_test.cpp

View workflow job for this annotation

GitHub Actions / cpp-linter

Run clang-format on libs/client-sdk/tests/flag_updater_test.cpp

File libs/client-sdk/tests/flag_updater_test.cpp does not conform to Custom style guidelines. (lines 210)

#include <launchdarkly/context_builder.hpp>
#include <launchdarkly/data/evaluation_detail_internal.hpp>
Expand Down Expand Up @@ -42,7 +42,7 @@
std::nullopt}}}}}});

EXPECT_FALSE(manager.GetAll().empty());
EXPECT_EQ("test", manager.Get("flagA")->item.value().Detail().Value());

Check warning on line 45 in libs/client-sdk/tests/flag_updater_test.cpp

View workflow job for this annotation

GitHub Actions / cpp-linter

/libs/client-sdk/tests/flag_updater_test.cpp:45:23 [bugprone-unchecked-optional-access]

unchecked access to optional value
}

TEST(FlagUpdaterDataTests, HandlesSecondInit) {
Expand All @@ -66,7 +66,7 @@
std::nullopt}}}}}});

EXPECT_FALSE(manager.GetAll().empty());
EXPECT_EQ("test", manager.Get("flagB")->item.value().Detail().Value());

Check warning on line 69 in libs/client-sdk/tests/flag_updater_test.cpp

View workflow job for this annotation

GitHub Actions / cpp-linter

/libs/client-sdk/tests/flag_updater_test.cpp:69:23 [bugprone-unchecked-optional-access]

unchecked access to optional value
EXPECT_FALSE(manager.Get("flagA"));
}

Expand All @@ -89,8 +89,8 @@
std::nullopt}}});

EXPECT_FALSE(manager.GetAll().empty());
EXPECT_EQ("test", manager.Get("flagA")->item.value().Detail().Value());

Check warning on line 92 in libs/client-sdk/tests/flag_updater_test.cpp

View workflow job for this annotation

GitHub Actions / cpp-linter

/libs/client-sdk/tests/flag_updater_test.cpp:92:23 [bugprone-unchecked-optional-access]

unchecked access to optional value
EXPECT_EQ("second", manager.Get("flagB")->item.value().Detail().Value());

Check warning on line 93 in libs/client-sdk/tests/flag_updater_test.cpp

View workflow job for this annotation

GitHub Actions / cpp-linter

/libs/client-sdk/tests/flag_updater_test.cpp:93:25 [bugprone-unchecked-optional-access]

unchecked access to optional value
}

TEST(FlagUpdaterDataTests, HandlePatchUpdateFlag) {
Expand All @@ -112,7 +112,7 @@
std::nullopt}}});

EXPECT_FALSE(manager.GetAll().empty());
EXPECT_EQ("second", manager.Get("flagA")->item.value().Detail().Value());

Check warning on line 115 in libs/client-sdk/tests/flag_updater_test.cpp

View workflow job for this annotation

GitHub Actions / cpp-linter

/libs/client-sdk/tests/flag_updater_test.cpp:115:25 [bugprone-unchecked-optional-access]

unchecked access to optional value
}

TEST(FlagUpdaterDataTests, HandlePatchOutOfOrder) {
Expand All @@ -134,7 +134,7 @@
std::nullopt}}});

EXPECT_FALSE(manager.GetAll().empty());
EXPECT_EQ("test", manager.Get("flagA")->item.value().Detail().Value());

Check warning on line 137 in libs/client-sdk/tests/flag_updater_test.cpp

View workflow job for this annotation

GitHub Actions / cpp-linter

/libs/client-sdk/tests/flag_updater_test.cpp:137:23 [bugprone-unchecked-optional-access]

unchecked access to optional value
}

TEST(FlagUpdaterDataTests, HandleDelete) {
Expand Down Expand Up @@ -172,7 +172,7 @@
ItemDescriptor{Tombstone{0}});

EXPECT_FALSE(manager.GetAll().empty());
EXPECT_EQ("test", manager.Get("flagA")->item.value().Detail().Value());

Check warning on line 175 in libs/client-sdk/tests/flag_updater_test.cpp

View workflow job for this annotation

GitHub Actions / cpp-linter

/libs/client-sdk/tests/flag_updater_test.cpp:175:23 [bugprone-unchecked-optional-access]

unchecked access to optional value
}

TEST(FlagUpdaterEventTests, InitialInitProducesNoEvents) {
Expand All @@ -183,7 +183,7 @@

std::atomic_bool got_event(false);
notifier->OnFlagChange(
"flagA", [&got_event](std::shared_ptr<FlagValueChangeEvent> event) {

Check warning on line 186 in libs/client-sdk/tests/flag_updater_test.cpp

View workflow job for this annotation

GitHub Actions / cpp-linter

/libs/client-sdk/tests/flag_updater_test.cpp:186:69 [performance-unnecessary-value-param]

the parameter 'event' is copied for each invocation but only used as a const reference; consider making it a const reference
got_event.store(true);
});

Expand All @@ -199,7 +199,7 @@
EXPECT_FALSE(got_event);
}

TEST(FlagUpdaterEventTests, SecondInitWithUpdateProducesEvents) {

Check warning on line 202 in libs/client-sdk/tests/flag_updater_test.cpp

View workflow job for this annotation

GitHub Actions / cpp-linter

/libs/client-sdk/tests/flag_updater_test.cpp:202:1 [readability-function-cognitive-complexity]

function 'TestBody' has cognitive complexity of 38 (threshold 25)
FlagStore manager;
FlagUpdater updater(manager);

Expand All @@ -207,13 +207,21 @@

std::atomic_bool got_event(false);
notifier->OnFlagChange(
"flagA", [&got_event](std::shared_ptr<FlagValueChangeEvent> event) {
"flagA", [&got_event, &manager](std::shared_ptr<FlagValueChangeEvent> event) {
got_event.store(true);

EXPECT_EQ("test", event->OldValue().AsString());
EXPECT_EQ("potato", event->NewValue().AsString());
EXPECT_EQ("flagA", event->FlagName());
EXPECT_FALSE(event->Deleted());

// The value in the store should be consistent with the new value.
EXPECT_EQ(event->NewValue().AsString(), manager.Get("flagA")
.get()
->item.value()
.Detail()
.Value()
.AsString());
});

updater.Init(
Expand Down Expand Up @@ -283,13 +291,21 @@

std::atomic_bool got_event(false);
notifier->OnFlagChange(
"flagA", [&got_event](std::shared_ptr<FlagValueChangeEvent> event) {
"flagA",
[&got_event, &manager](std::shared_ptr<FlagValueChangeEvent> event) {
got_event.store(true);

EXPECT_EQ("test", event->OldValue().AsString());
EXPECT_EQ("second", event->NewValue().AsString());
EXPECT_EQ("flagA", event->FlagName());
EXPECT_FALSE(event->Deleted());
// The value in the store should be consistent with the new value.
EXPECT_EQ(event->NewValue().AsString(), manager.Get("flagA")
.get()
->item.value()
.Detail()
.Value()
.AsString());
});

updater.Init(
Expand Down Expand Up @@ -317,13 +333,22 @@

std::atomic_bool got_event(false);
notifier->OnFlagChange(
"flagB", [&got_event](std::shared_ptr<FlagValueChangeEvent> event) {
"flagB",
[&got_event, &manager](std::shared_ptr<FlagValueChangeEvent> event) {
got_event.store(true);

EXPECT_TRUE(event->OldValue().IsNull());
EXPECT_EQ("second", event->NewValue().AsString());
EXPECT_EQ("flagB", event->FlagName());
EXPECT_FALSE(event->Deleted());

// The value in the store should be consistent with the new value.
EXPECT_EQ(event->NewValue().AsString(), manager.Get("flagB")
.get()
->item.value()
.Detail()
.Value()
.AsString());
});

updater.Init(
Expand Down
Loading