From 97ae0814c39b5e90c3444ba0260780441ca5bbfb Mon Sep 17 00:00:00 2001 From: tsaichristine Date: Wed, 18 Sep 2019 11:31:13 -0700 Subject: [PATCH] Fix log matching unit test bug - Update matcher in TestUidFieldMatcher unit test to have correct atom id - Add atom id check in matchesSimple Test: bit statsd_test:AtomMatcher.TestUidFieldMatcher Bug: 141174720 Fix: 141174720 Change-Id: Icbfea7e33876dea36d68d3e3d064581c5a621a77 --- cmds/statsd/src/matchers/matcher_util.cpp | 5 +++-- cmds/statsd/tests/LogEntryMatcher_test.cpp | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/cmds/statsd/src/matchers/matcher_util.cpp b/cmds/statsd/src/matchers/matcher_util.cpp index 10ac4a182f875..476fae37899dd 100644 --- a/cmds/statsd/src/matchers/matcher_util.cpp +++ b/cmds/statsd/src/matchers/matcher_util.cpp @@ -358,9 +358,10 @@ bool matchesSimple(const UidMap& uidMap, const FieldValueMatcher& matcher, bool matchesSimple(const UidMap& uidMap, const SimpleAtomMatcher& simpleMatcher, const LogEvent& event) { - if (simpleMatcher.field_value_matcher_size() <= 0) { - return event.GetTagId() == simpleMatcher.atom_id(); + if (event.GetTagId() != simpleMatcher.atom_id()) { + return false; } + for (const auto& matcher : simpleMatcher.field_value_matcher()) { if (!matchesSimple(uidMap, matcher, event.getValues(), 0, event.getValues().size(), 0)) { return false; diff --git a/cmds/statsd/tests/LogEntryMatcher_test.cpp b/cmds/statsd/tests/LogEntryMatcher_test.cpp index 70f0f6f75a593..441d3c8964671 100644 --- a/cmds/statsd/tests/LogEntryMatcher_test.cpp +++ b/cmds/statsd/tests/LogEntryMatcher_test.cpp @@ -330,6 +330,7 @@ TEST(AtomMatcherTest, TestUidFieldMatcher) { EXPECT_FALSE(matchesSimple(uidMap, *simpleMatcher, event)); // Tag found in kAtomsWithUidField and has matching uid + simpleMatcher->set_atom_id(TAG_ID_2); EXPECT_TRUE(matchesSimple(uidMap, *simpleMatcher, event2)); // Tag found in kAtomsWithUidField but has non-matching uid