Skip to content

Commit 64b5925

Browse files
tomokinathiroyuki-komatsu
authored andcommitted
Fix TSAN error in session_watch_dog_test.
From https://google.github.io/googletest/gmock_for_dummies.html#using-mocks-in-tests: > Important note: gMock requires expectations to be set before the mock functions are called, otherwise the behavior is undefined. Do not alternate between calls to EXPECT_CALL() and calls to the mock functions, and do not set any expectations on a mock after passing the mock to an API. This is the last (currently known) TSAN error in mozc :) PiperOrigin-RevId: 731217246
1 parent 914e134 commit 64b5925

File tree

1 file changed

+2
-16
lines changed

1 file changed

+2
-16
lines changed

src/session/session_watch_dog_test.cc

+2-16
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
namespace mozc {
5050
namespace {
5151

52-
using ::testing::Mock;
5352
using ::testing::Return;
5453

5554
// Returns the given CPU load values in order.
@@ -94,7 +93,7 @@ client::ClientMock *CreateMockClient() {
9493
TEST(SessionWatchDogTest, SessionWatchDogTest) {
9594
constexpr absl::Duration kInterval = absl::Seconds(1);
9695
auto *client = CreateMockClient();
97-
auto stats = std::make_unique<TestCPUStats>(std::vector<float>(10, 0.0f));
96+
auto stats = std::make_unique<TestCPUStats>(std::vector<float>(5, 0.0f));
9897
EXPECT_CALL(*client, Cleanup()).Times(5);
9998

10099
SessionWatchDog watchdog(kInterval, absl::WrapUnique(client),
@@ -105,16 +104,12 @@ TEST(SessionWatchDogTest, SessionWatchDogTest) {
105104
EXPECT_EQ(watchdog.interval(), kInterval);
106105

107106
absl::SleepFor(absl::Milliseconds(5500)); // 5.5 sec
108-
Mock::VerifyAndClearExpectations(&client);
109-
110-
EXPECT_CALL(*client, Cleanup()).Times(5);
111-
absl::SleepFor(absl::Milliseconds(5000)); // 10.5 sec
112107
}
113108

114109
TEST(SessionWatchDogTest, SessionWatchDogCPUStatsTest) {
115110
constexpr absl::Duration kInterval = absl::Seconds(1);
116111
auto *client = CreateMockClient();
117-
auto *cpu_loads = new TestCPUStats(std::vector<float>(20, 0.8f));
112+
auto *cpu_loads = new TestCPUStats(std::vector<float>(5, 0.8f));
118113

119114
mozc::SessionWatchDog watchdog(kInterval, absl::WrapUnique(client),
120115
absl::WrapUnique(cpu_loads));
@@ -123,15 +118,6 @@ TEST(SessionWatchDogTest, SessionWatchDogCPUStatsTest) {
123118
absl::SleepFor(absl::Milliseconds(100));
124119
EXPECT_EQ(watchdog.interval(), kInterval);
125120
absl::SleepFor(absl::Milliseconds(5500)); // 5.5 sec
126-
127-
// not called
128-
Mock::VerifyAndClearExpectations(&client);
129-
130-
// CPU loads become low
131-
EXPECT_CALL(*client, Cleanup()).Times(5);
132-
cpu_loads->Set(std::vector<float>(20, 0.0f));
133-
134-
absl::SleepFor(absl::Milliseconds(5000)); // 5 sec
135121
}
136122

137123
TEST(SessionWatchDogTest, SessionCanSendCleanupCommandTest) {

0 commit comments

Comments
 (0)