Skip to content

Commit

Permalink
add SLEEPY_DURATION to FethcerConfig and use it for the nextUpdateTim…
Browse files Browse the repository at this point in the history
…e calculation

Signed-off-by: Benjamin Brahmer <[email protected]>
  • Loading branch information
Grotax committed Jan 2, 2025
1 parent 548f932 commit 73eb5af
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
6 changes: 6 additions & 0 deletions lib/Config/FetcherConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
5 changes: 4 additions & 1 deletion lib/Fetcher/FeedFetcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}',
[
Expand Down
11 changes: 8 additions & 3 deletions tests/updater/update.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 73eb5af

Please sign in to comment.