Commit 6dc28b99 authored by Charles Zhao's avatar Charles Zhao Committed by Commit Bot

cros: Fix two flaky tests.

Both tests fail because the proto serialization is not deterministic.

Change-Id: I3b99faa03c55b3333c1d03e05258985e6f8ddaa5

Bug: 884140
Change-Id: I3b99faa03c55b3333c1d03e05258985e6f8ddaa5
Reviewed-on: https://chromium-review.googlesource.com/1233096
Commit-Queue: Charles . <charleszhao@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#592776}
parent a6f711fd
......@@ -75,8 +75,22 @@ TEST_F(SerializedMrfuAppLaunchPredictorTest, ToProto) {
predictor.Train(kTarget1);
predictor.Train(kTarget2);
EXPECT_EQ(predictor.ToProto().SerializeAsString(),
proto_.SerializeAsString());
// Check predictor.ToProto() is the same as proto_.
const SerializedMrfuAppLaunchPredictorProto proto_expected =
proto_.serialized_mrfu_app_launch_predictor();
const SerializedMrfuAppLaunchPredictorProto proto_trained =
predictor.ToProto().serialized_mrfu_app_launch_predictor();
EXPECT_EQ(proto_trained.num_of_trains(), proto_expected.num_of_trains());
EXPECT_EQ(proto_trained.scores().size(), proto_expected.scores().size());
for (const auto& pair : proto_trained.scores()) {
const auto find_expected = proto_expected.scores().find(pair.first);
EXPECT_TRUE(find_expected != proto_expected.scores().end());
const auto& score_expected = find_expected->second;
const auto& score_trained = pair.second;
EXPECT_EQ(score_trained.num_of_trains_at_last_update(),
score_expected.num_of_trains_at_last_update());
EXPECT_FLOAT_EQ(score_trained.last_score(), score_expected.last_score());
}
}
TEST_F(SerializedMrfuAppLaunchPredictorTest, FromProto) {
......
......@@ -172,8 +172,7 @@ TEST_F(AppSearchResultRankerSerializationTest,
EXPECT_TRUE(ranker.Rank().empty());
}
// Test is flaky. See https://crbug.com/884140
TEST_F(AppSearchResultRankerSerializationTest, DISABLED_SaveToDiskSucceed) {
TEST_F(AppSearchResultRankerSerializationTest, SaveToDiskSucceed) {
// Construct ranker.
AppSearchResultRanker ranker(temp_dir_.GetPath(), kNotAnEphemeralUser);
// Wait for the loading to finish.
......@@ -201,10 +200,15 @@ TEST_F(AppSearchResultRankerSerializationTest, DISABLED_SaveToDiskSucceed) {
// Expect the predictor file is created.
EXPECT_TRUE(base::PathExists(predictor_filename_));
// Expect the content to be proto_str_.
std::string str_written;
EXPECT_TRUE(base::ReadFileToString(predictor_filename_, &str_written));
EXPECT_EQ(str_written, proto_str_);
// Construct a second ranker from saved model file.
AppSearchResultRanker second_ranker(temp_dir_.GetPath(), kNotAnEphemeralUser);
// Wait for the loading to finish.
Wait();
// Check the second ranker is loaded correctly.
EXPECT_THAT(second_ranker.Rank(),
UnorderedElementsAre(Pair(kTarget1, FloatEq(1.0f)),
Pair(kTarget2, FloatEq(2.0f))));
}
} // namespace app_list
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment