|
12 | 12 | // See the License for the specific language governing permissions and |
13 | 13 | // limitations under the License. |
14 | 14 |
|
| 15 | +#include "common/TimeUtil.h" |
15 | 16 | #include "config/OnetimeConfigInfoManager.h" |
16 | 17 | #include "config/PipelineConfig.h" |
17 | 18 | #include "logger/Logger.h" |
@@ -71,29 +72,44 @@ void PipelineConfigUnittest::TestOnetimeConfig() const { |
71 | 72 | auto configJson = make_unique<Json::Value>(); |
72 | 73 | (*configJson)["global"]["ExcutionTimeout"] = true; |
73 | 74 |
|
| 75 | + auto now = std::chrono::system_clock::now(); |
| 76 | + ScopedClockOverride clockGuard(now); |
74 | 77 | ConfigMock config("test", std::move(configJson), filepath); |
75 | 78 | APSARA_TEST_TRUE(config.GetExpireTimeIfOneTime((*config.mDetail)["global"])); |
76 | | - APSARA_TEST_EQUAL(time(nullptr) + 604800U, config.mOnetimeExpireTime); |
| 79 | + APSARA_TEST_EQUAL( |
| 80 | + static_cast<uint32_t>(std::chrono::duration_cast<std::chrono::seconds>(now.time_since_epoch()).count()) |
| 81 | + + 604800U, |
| 82 | + config.mOnetimeExpireTime); |
77 | 83 | APSARA_TEST_FALSE(config.mIsRunningBeforeStart); |
78 | 84 | } |
79 | 85 | { |
80 | 86 | // ExcutionTimeout too small |
81 | 87 | auto configJson = make_unique<Json::Value>(); |
82 | 88 | (*configJson)["global"]["ExcutionTimeout"] = 1U; |
83 | 89 |
|
| 90 | + auto now = std::chrono::system_clock::now(); |
| 91 | + ScopedClockOverride clockGuard(now); |
84 | 92 | ConfigMock config("test", std::move(configJson), filepath); |
85 | 93 | APSARA_TEST_TRUE(config.GetExpireTimeIfOneTime((*config.mDetail)["global"])); |
86 | | - APSARA_TEST_EQUAL(time(nullptr) + 600U, config.mOnetimeExpireTime); |
| 94 | + APSARA_TEST_EQUAL( |
| 95 | + static_cast<uint32_t>(std::chrono::duration_cast<std::chrono::seconds>(now.time_since_epoch()).count()) |
| 96 | + + 600U, |
| 97 | + config.mOnetimeExpireTime); |
87 | 98 | APSARA_TEST_FALSE(config.mIsRunningBeforeStart); |
88 | 99 | } |
89 | 100 | { |
90 | 101 | // ExcutionTimeout too large |
91 | 102 | auto configJson = make_unique<Json::Value>(); |
92 | 103 | (*configJson)["global"]["ExcutionTimeout"] = 1000000U; |
93 | 104 |
|
| 105 | + auto now = std::chrono::system_clock::now(); |
| 106 | + ScopedClockOverride clockGuard(now); |
94 | 107 | ConfigMock config("test", std::move(configJson), filepath); |
95 | 108 | APSARA_TEST_TRUE(config.GetExpireTimeIfOneTime((*config.mDetail)["global"])); |
96 | | - APSARA_TEST_EQUAL(time(nullptr) + 604800U, config.mOnetimeExpireTime); |
| 109 | + APSARA_TEST_EQUAL( |
| 110 | + static_cast<uint32_t>(std::chrono::duration_cast<std::chrono::seconds>(now.time_since_epoch()).count()) |
| 111 | + + 604800U, |
| 112 | + config.mOnetimeExpireTime); |
97 | 113 | APSARA_TEST_FALSE(config.mIsRunningBeforeStart); |
98 | 114 | } |
99 | 115 |
|
@@ -142,9 +158,14 @@ void PipelineConfigUnittest::TestOnetimeConfig() const { |
142 | 158 | auto configJson = make_unique<Json::Value>(); |
143 | 159 | (*configJson)["global"]["ExcutionTimeout"] = 3600U; |
144 | 160 |
|
| 161 | + auto now = std::chrono::system_clock::now(); |
| 162 | + ScopedClockOverride clockGuard(now); |
145 | 163 | ConfigMock config("new_config", std::move(configJson), filepath); |
146 | 164 | APSARA_TEST_TRUE(config.GetExpireTimeIfOneTime((*config.mDetail)["global"])); |
147 | | - APSARA_TEST_EQUAL(time(nullptr) + 3600U, config.mOnetimeExpireTime); |
| 165 | + APSARA_TEST_EQUAL( |
| 166 | + static_cast<uint32_t>(std::chrono::duration_cast<std::chrono::seconds>(now.time_since_epoch()).count()) |
| 167 | + + 3600U, |
| 168 | + config.mOnetimeExpireTime); |
148 | 169 | APSARA_TEST_FALSE(config.mIsRunningBeforeStart); |
149 | 170 | APSARA_TEST_EQUAL(sConfigManager->mConfigCheckpointMap.end(), |
150 | 171 | sConfigManager->mConfigCheckpointMap.find("new_config")); |
|
0 commit comments