From 73eb5af7525f225f7a80557bc79119429da33399 Mon Sep 17 00:00:00 2001 From: Benjamin Brahmer Date: Tue, 31 Dec 2024 12:48:17 +0100 Subject: [PATCH 1/2] add SLEEPY_DURATION to FethcerConfig and use it for the nextUpdateTime calculation Signed-off-by: Benjamin Brahmer --- CHANGELOG.md | 2 +- lib/Config/FetcherConfig.php | 6 ++++++ lib/Fetcher/FeedFetcher.php | 5 ++++- tests/updater/update.bats | 11 ++++++++--- 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 626471219..61fb7461f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,7 @@ You can also check [on GitHub](https://github.com/nextcloud/news/releases), the # Unreleased ## [25.x.x] ### Changed - +- Set maximum delay for updates to "in one day" (#3015) ### Fixed - OPML import use text field for title if title field is missing (#3016) diff --git a/lib/Config/FetcherConfig.php b/lib/Config/FetcherConfig.php index d0da1da6a..7a8fa494f 100644 --- a/lib/Config/FetcherConfig.php +++ b/lib/Config/FetcherConfig.php @@ -67,6 +67,12 @@ class FetcherConfig 'application/atom+xml;q=0.6, application/xml;q=0.4, ' . 'text/xml;q=0.4, */*;q=0.2'; + /** + * Duration after which the feed is considered sleepy. + * @var int + */ + public const SLEEPY_DURATION = 86400; + /** * FetcherConfig constructor. * diff --git a/lib/Fetcher/FeedFetcher.php b/lib/Fetcher/FeedFetcher.php index b8e1ab81e..33bade565 100755 --- a/lib/Fetcher/FeedFetcher.php +++ b/lib/Fetcher/FeedFetcher.php @@ -145,7 +145,10 @@ public function fetch( $location ); - $feed->setNextUpdateTime($resource->getNextUpdate()?->getTimestamp()); + $feed->setNextUpdateTime(nextUpdateTime: $resource->getNextUpdate( + sleepyDuration: $this->fetcherConfig::SLEEPY_DURATION + )?->getTimestamp()); + $this->logger->debug( 'Feed {url} was parsed and nextUpdateTime is {nextUpdateTime}', [ diff --git a/tests/updater/update.bats b/tests/updater/update.bats index 5c17d97d0..553a76a9d 100644 --- a/tests/updater/update.bats +++ b/tests/updater/update.bats @@ -76,9 +76,9 @@ teardown() { # Get the current time current_time=$(date +%s) - # Calculate the expected time range (+1 hour with some tolerance) - expected_time_min=$((current_time + 3600 - 60)) # 1 hour - 1 minute tolerance - expected_time_max=$((current_time + 3600 + 60)) # 1 hour + 1 minute tolerance + # Calculate the expected time range (+1 day with some tolerance) + expected_time_min=$((current_time + 86400 - 60)) # 1 hour - 1 minute tolerance + expected_time_max=$((current_time + 86400 + 60)) # 1 hour + 1 minute tolerance php ${BATS_TEST_DIRNAME}/../test_helper/php-feed-generator/feed-generator.php -a 15 -s 9 -f ${BATS_TEST_DIRNAME}/../test_helper/feeds/test.xml # Trigger Update @@ -88,6 +88,11 @@ teardown() { UpdateTime2=$(http --ignore-stdin -b -a ${user}:${APP_PASSWORD} GET ${BASE_URLv1}/feeds | jq '.feeds | .[0].nextUpdateTime') + # Check if UpdateTime2 is within the expected range and print it if not + if [[ $UpdateTime2 -lt $expected_time_min || $UpdateTime2 -gt $expected_time_max ]]; then + echo "UpdateTime2 is out of range: $UpdateTime2" + fi + # Assert that UpdateTime2 is within the expected range run bash -c "[[ $UpdateTime2 -ge $expected_time_min && $UpdateTime2 -le $expected_time_max ]]" assert_success From 7e085812df15ed91c76fb888d1835cc0dcd7cd72 Mon Sep 17 00:00:00 2001 From: Benjamin Brahmer Date: Thu, 2 Jan 2025 11:03:33 +0100 Subject: [PATCH 2/2] don't check timestamp twice Signed-off-by: Benjamin Brahmer --- tests/updater/update.bats | 37 ++----------------------------------- 1 file changed, 2 insertions(+), 35 deletions(-) diff --git a/tests/updater/update.bats b/tests/updater/update.bats index 553a76a9d..d1f00cbc2 100644 --- a/tests/updater/update.bats +++ b/tests/updater/update.bats @@ -88,13 +88,8 @@ teardown() { UpdateTime2=$(http --ignore-stdin -b -a ${user}:${APP_PASSWORD} GET ${BASE_URLv1}/feeds | jq '.feeds | .[0].nextUpdateTime') - # Check if UpdateTime2 is within the expected range and print it if not - if [[ $UpdateTime2 -lt $expected_time_min || $UpdateTime2 -gt $expected_time_max ]]; then - echo "UpdateTime2 is out of range: $UpdateTime2" - fi - - # Assert that UpdateTime2 is within the expected range - run bash -c "[[ $UpdateTime2 -ge $expected_time_min && $UpdateTime2 -le $expected_time_max ]]" + # Assert that UpdateTime2 is within the expected range and print the timestamp if not + run bash -c "[[ \$UpdateTime2 -ge \$expected_time_min && \$UpdateTime2 -le \$expected_time_max ]] || echo \"UpdateTime2 is out of range: \$UpdateTime2\"" assert_success } @@ -128,34 +123,6 @@ teardown() { assert_output --partial "${ID_LIST1[*]}" } -# older date is not a thing anymore -#@test "[$TESTSUITE] Test feed with 'outdated' items https://github.com/nextcloud/news/issues/2236 " { -# # Create Feed, for the first fetch a timestamp today -1 year is used. -# FEEDID=$(http --ignore-stdin -b -a ${user}:${APP_PASSWORD} POST ${BASE_URLv1}/feeds url=$TEST_FEED | grep -Po '"id":\K([0-9]+)') -# -# sleep 2 -# -# # Get Items -# ID_LIST1=($(http --ignore-stdin -b -a ${user}:${APP_PASSWORD} GET ${BASE_URLv1}/items | grep -Po '"id":\K([0-9]+)' | tr '\n' ' ')) -# -# # Generate Feed with older items (-o yes) -# php ${BATS_TEST_DIRNAME}/../test_helper/php-feed-generator/feed-generator.php -a 15 -s 9 -f ${BATS_TEST_DIRNAME}/../test_helper/feeds/test.xml -o yes -# -# # Trigger Update -# http --ignore-stdin -b -a ${user}:${APP_PASSWORD} GET ${BASE_URLv1}/feeds/update userId=${user} feedId=$FEEDID -# -# sleep 2 -# -# # Get Items again -# ID_LIST2=($(http --ignore-stdin -b -a ${user}:${APP_PASSWORD} GET ${BASE_URLv1}/items | grep -Po '"id":\K([0-9]+)' | tr '\n' ' ')) -# -# output="${ID_LIST2[*]}" -# -# # Check that they are not equal but that they match partially. -# assert_not_equal "${ID_LIST1[*]}" "${ID_LIST2[*]}" -# assert_output --partial "${ID_LIST1[*]}" -#} - @test "[$TESTSUITE] Test purge with small feed" { # Disable useNextUpdateTime ./occ config:app:set news useNextUpdateTime --value=false