-
Notifications
You must be signed in to change notification settings - Fork 11
Conversation
test/resource_unittest.cc
Outdated
|
|
||
| TEST(ResourceTest, Type) { | ||
| std::map<std::string, std::string> m; | ||
| google::MonitoredResource mr("type", m); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Optional] Let's go with something other than "type", to make sure the field name does not accidentally leak into the value. I would propose something like "some_resource".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea, changed.
test/resource_unittest.cc
Outdated
| } | ||
|
|
||
| TEST(ResourceTest, Labels) { | ||
| std::map<std::string, std::string> m; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
std::map<std::string, std::string> m{{"foo", "bar"}, {"bar", "baz"}};
google::MonitoredResource mr("", m);or even
google::MonitoredResource mr("", {{"foo", "bar"}, {"bar", "baz"}});There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, changed everywhere.
test/resource_unittest.cc
Outdated
| TEST(ResourceTest, BasicEquality) { | ||
| std::map<std::string, std::string> m1; | ||
| std::map<std::string, std::string> m2; | ||
| google::MonitoredResource mr1("", m1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
google::MonitoredResource mr1("", {});
google::MonitoredResource mr2("", {});There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed everywhere.
test/resource_unittest.cc
Outdated
| google::MonitoredResource mr1("", m1); | ||
| google::MonitoredResource mr2("", m2); | ||
|
|
||
| EXPECT_TRUE(mr1 == mr2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
EXPECT_EQ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed.
test/resource_unittest.cc
Outdated
| google::MonitoredResource mr1("2", m1); | ||
| google::MonitoredResource mr2("1", m2); | ||
|
|
||
| EXPECT_TRUE(mr1 < mr2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
EXPECT_LT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed.
test/resource_unittest.cc
Outdated
| google::MonitoredResource mr1("", m1); | ||
| google::MonitoredResource mr2("", m2); | ||
|
|
||
| EXPECT_FALSE(mr1 == mr2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
EXPECT_NE?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed. I had to add the != operator to resource, but luckily the NE test will cover that as well.
7a96877 to
eeeb6e6
Compare
igorpeshansky
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One more.
test/resource_unittest.cc
Outdated
|
|
||
| TEST(ResourceTest, Type) { | ||
| std::map<std::string, std::string> m; | ||
| google::MonitoredResource mr("some_resource", m); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
google::MonitoredResource mr("some_resource", {}).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed, thanks
| google::MonitoredResource mr1("2", {}); | ||
| google::MonitoredResource mr2("1", {}); | ||
|
|
||
| EXPECT_LT(mr1, mr2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one confuses me, mr1's key is 2, how is 2 less than 1?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Simple -- it's a bug; the implementation is inverted. :-)
Yay for unit tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a bug: "2" < "1" and "b" < "a". This is confusing, so I added simple examples above the expects to make it more clear.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's be careful here. The specific implementation of operator< for resources does have a bug, because x < y becomes x.operator<(y), which, in the current implementation would evaluate y.type_ < x.type_ || (y.type_ == x.type_ && y.labels_ < x.labels_), which is clearly wrong.
The test @ACEmilG ran to get "2" < "1" is flawed. If you compare std::strings, it would behave as expected: std::string("1") < std::string("2"). When you compare char* values, you're comparing pointers, so the order is essentially random, so that doesn't count.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, thanks for clarification!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. It's funny that ultimately, the behavior of the operator didn't matter as long as it's stable, because all it was needed for was using MonitoredResource as a key in std::map. But it's good to get it right.
| google::MonitoredResource mr2("", {{"a", "a"}}); | ||
|
|
||
| EXPECT_NE(mr1, mr2); | ||
| EXPECT_LT(mr1, mr2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same confusion here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See above.
| google::MonitoredResource mr1("2", {}); | ||
| google::MonitoredResource mr2("1", {}); | ||
|
|
||
| EXPECT_LT(mr1, mr2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's be careful here. The specific implementation of operator< for resources does have a bug, because x < y becomes x.operator<(y), which, in the current implementation would evaluate y.type_ < x.type_ || (y.type_ == x.type_ && y.labels_ < x.labels_), which is clearly wrong.
The test @ACEmilG ran to get "2" < "1" is flawed. If you compare std::strings, it would behave as expected: std::string("1") < std::string("2"). When you compare char* values, you're comparing pointers, so the order is essentially random, so that doesn't count.
test/resource_unittest.cc
Outdated
| google::MonitoredResource mr1("2", {}); | ||
| google::MonitoredResource mr2("1", {}); | ||
|
|
||
| EXPECT_LT("2", "1"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Leftover debug code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed. It was as an example (for my mistaken understanding of the comparison)
test/resource_unittest.cc
Outdated
| google::MonitoredResource mr1("", {{"b", "b"}}); | ||
| google::MonitoredResource mr2("", {{"a", "a"}}); | ||
|
|
||
| EXPECT_LT("b", "a"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Leftover debug code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed.
igorpeshansky
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM ![]()
Don't forget to "squash and merge".
| google::MonitoredResource mr1("2", {}); | ||
| google::MonitoredResource mr2("1", {}); | ||
|
|
||
| EXPECT_LT(mr1, mr2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. It's funny that ultimately, the behavior of the operator didn't matter as long as it's stable, because all it was needed for was using MonitoredResource as a key in std::map. But it's good to get it right.
bmoyles0117
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
No description provided.