bneradt commented on code in PR #13758: URL: https://github.com/apache/trafficserver/pull/13758#discussion_r4149429480
########## src/proxy/logging/unit-tests/test_LogRolling.cc: ########## @@ -0,0 +1,224 @@ +/** @file + + Unit tests for time-based log rolling. + + LogObject::roll_files() takes the current time as an argument, so these tests + drive it across a synthetic midnight rather than waiting out a real rolling + interval. The AuTest harness turns rolling off (a test running across 00:00 + must not have its logs renamed under it), so this is where automatic rolling + itself is covered. + + @section license License + + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + +#include <catch2/catch_test_macros.hpp> + +#include "iocore/utils/Machine.h" +#include "proxy/logging/Log.h" +#include "proxy/logging/LogConfig.h" +#include "proxy/logging/LogFile.h" +#include "proxy/logging/LogFormat.h" +#include "proxy/logging/LogObject.h" + +#include <unistd.h> + +#include <ctime> +#include <filesystem> +#include <fstream> +#include <iterator> +#include <memory> +#include <string> +#include <vector> + +namespace fs = std::filesystem; + +namespace +{ +constexpr int ONE_DAY = 86400; + +/// Local time @a days_ahead days from today at @a hour : @a min : @a sec. +/// seconds_to_next_roll() works in local time, so the boundaries are built the same way. +time_t +local_time(int days_ahead, int hour, int min, int sec) +{ + time_t now = time(nullptr); + struct tm lt; + localtime_r(&now, <); + lt.tm_mday += days_ahead; + lt.tm_hour = hour; + lt.tm_min = min; + lt.tm_sec = sec; + lt.tm_isdst = -1; + return mktime(<); Review Comment: [P2] Avoid constructing a synthetic boundary at a nonexistent local midnight The calendar-based increment still depends on the real date and timezone. Some zones advance their clock at 00:00: for a run on 2026-09-04 with TZ=America/Santiago, local_time(2, 0, 0, 1) requests 2026-09-06 00:00:01, which mktime normalizes to 01:00:01. I reproduced this normalization; seconds_to_next_roll then returns 82799, outside the ten-second rolling window, so REQUIRE(obj->roll_files(after) == 1) fails despite correct production behavior. America/Havana on 2026-03-08 has the same issue. Please use a controlled timezone/date for the synthetic fixture, or explicitly choose valid local-midnight boundaries. Capturing the base date once would also avoid separate helper calls straddling a real midnight. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
