Skip to content

Commit 6ea8b2f

Browse files
committed
update timer_test.cpp
1 parent f747833 commit 6ea8b2f

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

source/source_base/test/timer_test.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ class TimerTest : public testing::Test
4141
std::ofstream ofs;
4242
std::ifstream ifs;
4343
int T_Elapse = 100; // microseconds = 0.1 milliseconds
44+
void SetUp()
45+
{
46+
ModuleBase::timer::timer_pool.clear();
47+
}
4448
void TearDown()
4549
{
4650
remove("tmp");
@@ -94,7 +98,7 @@ TEST_F(TimerTest, write_to_json)
9498

9599
EXPECT_THAT(content,testing::HasSubstr("\"total\":"));
96100
EXPECT_THAT(content,testing::HasSubstr("\"sub\":[{\"class_name\":\"wavefunc\",\"sub\":[{\"name\":\"evc\",\"cpu_second\":"));
97-
EXPECT_THAT(content,testing::HasSubstr("\"calls\":2,\"cpu_second_per_call\":"));
101+
EXPECT_THAT(content,testing::HasSubstr("\"calls\":1,\"cpu_second_per_call\":"));
98102
EXPECT_THAT(content,testing::HasSubstr("\"cpu_second_per_total\":"));
99103
EXPECT_THAT(content,testing::HasSubstr("}]}]}"));
100104
ifs.close();
@@ -146,6 +150,8 @@ TEST_F(TimerTest, PrintAll)
146150

147151
TEST_F(TimerTest, PrintUntilNow)
148152
{
153+
ModuleBase::timer::start();
154+
std::this_thread::sleep_for(std::chrono::microseconds(T_Elapse));
149155
long double time = ModuleBase::timer::print_until_now();
150156
EXPECT_TRUE(time>0.0);
151157
}

0 commit comments

Comments
 (0)