From d7abac3ea9b10b6336181d8d0f3c9acd0d5d7722 Mon Sep 17 00:00:00 2001 From: David Zafman Date: Wed, 4 Nov 2020 09:20:17 -0800 Subject: [PATCH] test: unittest_osdscrub: Remove invalid hour test and add day of week testing Signed-off-by: David Zafman --- src/test/osd/TestOSDScrub.cc | 83 ++++++++++++++++++++++++++++-------- 1 file changed, 66 insertions(+), 17 deletions(-) diff --git a/src/test/osd/TestOSDScrub.cc b/src/test/osd/TestOSDScrub.cc index 4e37c474d37..45d79a18379 100644 --- a/src/test/osd/TestOSDScrub.cc +++ b/src/test/osd/TestOSDScrub.cc @@ -70,8 +70,26 @@ TEST(TestOSDScrub, scrub_time_permit) { mc.build_initial_monmap(); TestOSDScrub* osd = new TestOSDScrub(g_ceph_context, store, 0, ms, ms, ms, ms, ms, ms, ms, &mc, "", "", icp); + // These are now invalid + int err = g_ceph_context->_conf.set_val("osd_scrub_begin_hour", "24"); + ASSERT_TRUE(err < 0); + //GTEST_LOG_(INFO) << " osd_scrub_begin_hour = " << g_ceph_context->_conf.get_val("osd_scrub_begin_hour"); + + err = g_ceph_context->_conf.set_val("osd_scrub_end_hour", "24"); + ASSERT_TRUE(err < 0); + //GTEST_LOG_(INFO) << " osd_scrub_end_hour = " << g_ceph_context->_conf.get_val("osd_scrub_end_hour"); + + err = g_ceph_context->_conf.set_val("osd_scrub_begin_week_day", "7"); + ASSERT_TRUE(err < 0); + //GTEST_LOG_(INFO) << " osd_scrub_begin_week_day = " << g_ceph_context->_conf.get_val("osd_scrub_begin_week_day"); + + err = g_ceph_context->_conf.set_val("osd_scrub_end_week_day", "7"); + ASSERT_TRUE(err < 0); + //GTEST_LOG_(INFO) << " osd_scrub_end_week_day = " << g_ceph_context->_conf.get_val("osd_scrub_end_week_day"); + + // Test all day g_ceph_context->_conf.set_val("osd_scrub_begin_hour", "0"); - g_ceph_context->_conf.set_val("osd_scrub_end_hour", "24"); + g_ceph_context->_conf.set_val("osd_scrub_end_hour", "0"); g_ceph_context->_conf.apply_changes(nullptr); tm tm; tm.tm_isdst = -1; @@ -80,22 +98,6 @@ TEST(TestOSDScrub, scrub_time_permit) { bool ret = osd->scrub_time_permit(now); ASSERT_TRUE(ret); - g_ceph_context->_conf.set_val("osd_scrub_begin_hour", "24"); - g_ceph_context->_conf.set_val("osd_scrub_end_hour", "0"); - g_ceph_context->_conf.apply_changes(nullptr); - strptime("2015-01-16 12:05:13", "%Y-%m-%d %H:%M:%S", &tm); - now = utime_t(mktime(&tm), 0); - ret = osd->scrub_time_permit(now); - ASSERT_FALSE(ret); - - g_ceph_context->_conf.set_val("osd_scrub_begin_hour", "0"); - g_ceph_context->_conf.set_val("osd_scrub_end_hour", "0"); - g_ceph_context->_conf.apply_changes(nullptr); - strptime("2015-01-16 12:05:13", "%Y-%m-%d %H:%M:%S", &tm); - now = utime_t(mktime(&tm), 0); - ret = osd->scrub_time_permit(now); - ASSERT_TRUE(ret); - g_ceph_context->_conf.set_val("osd_scrub_begin_hour", "20"); g_ceph_context->_conf.set_val("osd_scrub_end_hour", "07"); g_ceph_context->_conf.apply_changes(nullptr); @@ -144,6 +146,53 @@ TEST(TestOSDScrub, scrub_time_permit) { ret = osd->scrub_time_permit(now); ASSERT_TRUE(ret); + // Sun = 0, Mon = 1, Tue = 2, Wed = 3, Thu = 4m, Fri = 5, Sat = 6 + // Jan 16, 2015 is a Friday (5) + // every day + g_ceph_context->_conf.set_val("osd_scrub_begin_week day", "0"); // inclusive + g_ceph_context->_conf.set_val("osd_scrub_end_week_day", "0"); // not inclusive + g_ceph_context->_conf.apply_changes(nullptr); + strptime("2015-01-16 04:05:13", "%Y-%m-%d %H:%M:%S", &tm); + now = utime_t(mktime(&tm), 0); + ret = osd->scrub_time_permit(now); + ASSERT_TRUE(ret); + + // test Sun - Thu + g_ceph_context->_conf.set_val("osd_scrub_begin_week day", "0"); // inclusive + g_ceph_context->_conf.set_val("osd_scrub_end_week_day", "5"); // not inclusive + g_ceph_context->_conf.apply_changes(nullptr); + strptime("2015-01-16 04:05:13", "%Y-%m-%d %H:%M:%S", &tm); + now = utime_t(mktime(&tm), 0); + ret = osd->scrub_time_permit(now); + ASSERT_FALSE(ret); + + // test Fri - Sat + g_ceph_context->_conf.set_val("osd_scrub_begin_week day", "5"); // inclusive + g_ceph_context->_conf.set_val("osd_scrub_end_week_day", "0"); // not inclusive + g_ceph_context->_conf.apply_changes(nullptr); + strptime("2015-01-16 04:05:13", "%Y-%m-%d %H:%M:%S", &tm); + now = utime_t(mktime(&tm), 0); + ret = osd->scrub_time_permit(now); + ASSERT_TRUE(ret); + + // Jan 14, 2015 is a Wednesday (3) + // test Tue - Fri + g_ceph_context->_conf.set_val("osd_scrub_begin_week day", "2"); // inclusive + g_ceph_context->_conf.set_val("osd_scrub_end_week_day", "6"); // not inclusive + g_ceph_context->_conf.apply_changes(nullptr); + strptime("2015-01-14 04:05:13", "%Y-%m-%d %H:%M:%S", &tm); + now = utime_t(mktime(&tm), 0); + ret = osd->scrub_time_permit(now); + ASSERT_TRUE(ret); + + // Test Sat - Sun + g_ceph_context->_conf.set_val("osd_scrub_begin_week day", "6"); // inclusive + g_ceph_context->_conf.set_val("osd_scrub_end_week_day", "1"); // not inclusive + g_ceph_context->_conf.apply_changes(nullptr); + strptime("2015-01-14 04:05:13", "%Y-%m-%d %H:%M:%S", &tm); + now = utime_t(mktime(&tm), 0); + ret = osd->scrub_time_permit(now); + ASSERT_FALSE(ret); } // Local Variables: -- 2.39.5