bryancall commented on code in PR #13758: URL: https://github.com/apache/trafficserver/pull/13758#discussion_r4149477145
########## 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: Good catch, and I reproduced both: with the clock on 2026-09-04 in America/Santiago and 2026-03-06 in America/Havana, the previous version fails the midnight roll. Fixed in 734cafe9bc: the test now sets TZ=UTC for the process and builds every boundary from a fixed date (January 2030) with timegm, so each midnight exists and nothing reads the real clock between calls. It passes under those two cases, two days before the Los Angeles DST change, and in UTC, Los Angeles and Kolkata. -- 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]
