Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test function MockTimeEnv.SleepForMicroseconds() #7293

Closed
wants to merge 3 commits into from

Conversation

jay-zhuang
Copy link
Contributor

@jay-zhuang jay-zhuang commented Aug 20, 2020

And change the internal time value from seconds to microseconds.

Copy link
Contributor

@mrambacher mrambacher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Can you please provide a comment somewhere as to the impetus for this change?

@jay-zhuang jay-zhuang changed the title [WIP] Change MockTimeEnv second to microsecond Add test function MockTimeEnv.SleepForMicroseconds() Aug 20, 2020
@jay-zhuang jay-zhuang force-pushed the mock_time branch 2 times, most recently from f8fd334 to 95f8538 Compare August 20, 2020 22:15
@jay-zhuang jay-zhuang removed the WIP Work in progress label Aug 20, 2020
@jay-zhuang jay-zhuang marked this pull request as ready for review August 20, 2020 22:48
Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jay-zhuang has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

Copy link
Contributor

@pdillinger pdillinger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some recommendations

@@ -38,8 +40,7 @@ TEST_F(StatsDumpSchedulerTest, Basic) {
options.stats_dump_period_sec = kPeriodSec;
options.stats_persist_period_sec = kPeriodSec;
options.create_if_missing = true;
int mock_time_sec = 0;
mock_env_->set_current_time(mock_time_sec);
mock_env_->set_current_time(0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should not be necessary, right? From #7101,

Removed unnecessary resetting of mock times to 0 in many tests. RocksDB
deals in relative time. Any behaviors relying on absolute date/time are likely
a bug. (The above test DBSSTTest.GetTotalSstFilesSize was the only one
clearly injecting a specific absolute time for actual testing convenience.) Just
in case I misunderstood some test, I put this note in each replacement:
// NOTE: Presumed unnecessary and removed: resetting mock time in env

(And more below)

@@ -48,15 +48,16 @@ class StatsHistoryTest : public DBTestBase {
StatsDumpTestScheduler::Default(mock_env_.get());
});
}

const int kSecond = 1000000;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even though I originally named this 🤪, I now recommend kUsPerSec

timer.TEST_WaitForRun([&] { mock_env_->set_current_time(mock_time_sec); });
uint64_t next_abs_interval_time_us = kInitDelayUs + kRepeatUs;
timer.TEST_WaitForRun([&] {
mock_env_->set_current_time(next_abs_interval_time_us / 1000000);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recommend / kSecond (or renamed)


int mock_time_sec = 0;
mock_env_->set_current_time(mock_time_sec);
mock_env_->set_current_time(0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK to keep this one if it keeps this test simpler :)

dbfull()->TEST_WaitForStatsDumpRun(
[&] { mock_env_->set_current_time(mock_time_sec); });
[&] { mock_env_->SleepForMicroseconds(kPeriodSec * kSecond); });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're still mixing seconds and microseconds in tests, we might as well add SleepForSeconds also (like SpecialEnv) to minimize conversions.

And change the internal time value from seconds to microseconds.
@facebook-github-bot
Copy link
Contributor

@jay-zhuang has updated the pull request. You must reimport the pull request before landing.

@facebook-github-bot
Copy link
Contributor

@jay-zhuang has updated the pull request. You must reimport the pull request before landing.

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jay-zhuang has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@jay-zhuang merged this pull request in 187964a.

codingrhythm pushed a commit to SafetyCulture/rocksdb that referenced this pull request Mar 5, 2021
Summary:
And change the internal time value from seconds to microseconds.

Pull Request resolved: facebook#7293

Reviewed By: pdillinger

Differential Revision: D23253751

Pulled By: jay-zhuang

fbshipit-source-id: 36aa9376b8801b85bd10163173590a17cf4f3a3a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants