From 08553eee74af6cf1b2ae2336503c1ba0da12b845 Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Thu, 17 Sep 2020 17:08:17 +0000 Subject: [PATCH 1/4] fix context --- api/include/opentelemetry/context/context.h | 2 +- api/test/context/context_test.cc | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/api/include/opentelemetry/context/context.h b/api/include/opentelemetry/context/context.h index 06b95a6248..48b17b1190 100644 --- a/api/include/opentelemetry/context/context.h +++ b/api/include/opentelemetry/context/context.h @@ -40,7 +40,7 @@ class Context Context SetValues(T &values) noexcept { Context context = Context(values); - nostd::shared_ptr &last = context.head_; + nostd::shared_ptr last = context.head_; while (last->next_ != nullptr) { last = last->next_; diff --git a/api/test/context/context_test.cc b/api/test/context/context_test.cc index f9a6dfbfd4..6568d2eacf 100644 --- a/api/test/context/context_test.cc +++ b/api/test/context/context_test.cc @@ -78,14 +78,16 @@ TEST(ContextTest, ContextInheritance) { using M = std::map; - M m1 = {{"test_key", (int64_t)123}, {"foo_key", (int64_t)456}}; - M m2 = {{"other_key", (int64_t)789}}; + M m1 = {{"test_key", (int64_t)123}, {"foo_key", (int64_t)321}}; + M m2 = {{"other_key", (int64_t)789}, {"another_key", (int64_t)987}}; context::Context test_context = context::Context(m1); context::Context foo_context = test_context.SetValues(m2); EXPECT_EQ(nostd::get(foo_context.GetValue("test_key")), 123); - EXPECT_EQ(nostd::get(foo_context.GetValue("foo_key")), 456); + EXPECT_EQ(nostd::get(foo_context.GetValue("foo_key")), 321); + EXPECT_EQ(nostd::get(foo_context.GetValue("other_key")),789); + EXPECT_EQ(nostd::get(foo_context.GetValue("another_key")),987); } // Tests that copying a context copies the key value pairs as expected. From 7573e42ea662c835b3fcbef61cb7feebba3b6579 Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Thu, 17 Sep 2020 18:01:59 +0000 Subject: [PATCH 2/4] fix nullptr --- api/include/opentelemetry/context/context.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/include/opentelemetry/context/context.h b/api/include/opentelemetry/context/context.h index 48b17b1190..c807bad81e 100644 --- a/api/include/opentelemetry/context/context.h +++ b/api/include/opentelemetry/context/context.h @@ -110,7 +110,7 @@ class Context // Builds a data list off of a key and value iterable and returns the head template - DataList(const T &keys_and_vals) : key_{nullptr} + DataList(const T &keys_and_vals) : key_{nullptr}, next_(nostd::shared_ptr{nullptr}) { bool first = true; auto *node = this; From 14fcc643fcc2405ba8e456ddc1ccc527824cc96e Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Thu, 17 Sep 2020 18:05:21 +0000 Subject: [PATCH 3/4] add more tests --- api/test/context/context_test.cc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/api/test/context/context_test.cc b/api/test/context/context_test.cc index 6568d2eacf..f00c433100 100644 --- a/api/test/context/context_test.cc +++ b/api/test/context/context_test.cc @@ -88,6 +88,11 @@ TEST(ContextTest, ContextInheritance) EXPECT_EQ(nostd::get(foo_context.GetValue("foo_key")), 321); EXPECT_EQ(nostd::get(foo_context.GetValue("other_key")),789); EXPECT_EQ(nostd::get(foo_context.GetValue("another_key")),987); + + EXPECT_EQ(nostd::get(test_context.GetValue("other_key")),0); + EXPECT_EQ(nostd::get(test_context.GetValue("another_key")),0); + + } // Tests that copying a context copies the key value pairs as expected. From 5a32f1f43ef7da3c24dc1c24e32ded37eb0a1b0c Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Thu, 17 Sep 2020 18:11:15 +0000 Subject: [PATCH 4/4] fix format --- api/include/opentelemetry/context/context.h | 2 +- api/test/context/context_test.cc | 10 ++++------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/api/include/opentelemetry/context/context.h b/api/include/opentelemetry/context/context.h index c807bad81e..ed6a87eed0 100644 --- a/api/include/opentelemetry/context/context.h +++ b/api/include/opentelemetry/context/context.h @@ -39,7 +39,7 @@ class Context template Context SetValues(T &values) noexcept { - Context context = Context(values); + Context context = Context(values); nostd::shared_ptr last = context.head_; while (last->next_ != nullptr) { diff --git a/api/test/context/context_test.cc b/api/test/context/context_test.cc index f00c433100..66b7f34c45 100644 --- a/api/test/context/context_test.cc +++ b/api/test/context/context_test.cc @@ -86,13 +86,11 @@ TEST(ContextTest, ContextInheritance) EXPECT_EQ(nostd::get(foo_context.GetValue("test_key")), 123); EXPECT_EQ(nostd::get(foo_context.GetValue("foo_key")), 321); - EXPECT_EQ(nostd::get(foo_context.GetValue("other_key")),789); - EXPECT_EQ(nostd::get(foo_context.GetValue("another_key")),987); - - EXPECT_EQ(nostd::get(test_context.GetValue("other_key")),0); - EXPECT_EQ(nostd::get(test_context.GetValue("another_key")),0); - + EXPECT_EQ(nostd::get(foo_context.GetValue("other_key")), 789); + EXPECT_EQ(nostd::get(foo_context.GetValue("another_key")), 987); + EXPECT_EQ(nostd::get(test_context.GetValue("other_key")), 0); + EXPECT_EQ(nostd::get(test_context.GetValue("another_key")), 0); } // Tests that copying a context copies the key value pairs as expected.