mirror of
https://github.com/Cacti/plugin_thold.git
synced 2026-11-02 18:17:24 +09:00
* test: add the PHP 8.1 unit-test harness Same harness as #773 and #788, with gmp added to the image so the 64-bit counter arithmetic can be tested exactly. Signed-off-by: Thomas Vincent <thomasvincent@gmail.com> * fix(thold): correct the counter delta and the percent denominator A previous counter reading of exactly zero was treated as no reading at all, so the first interval after a device reboot reported a rate of zero. The wrap modulus was 2^32-1 and 2^64-1 rather than 2^32 and 2^64, losing one count per wrap, and the 64-bit literal exceeded PHP_INT_MAX so it was parsed as a float and lost about eleven bits before the subtraction. The percent-of denominator was cast to int, so a denominator below one truncated to zero and forced the result to zero, keeping any configured low threshold in permanent breach. Refs #785 Signed-off-by: Thomas Vincent <thomasvincent@gmail.com> * fix(daemon): store the previous reading in oldvalue, not a timestamp When a data source produced no sample this cycle the daemon wrote $currenttime - $rrd_step into oldvalue, so the next poll computed a delta against a Unix timestamp, took the overflow branch and fabricated a rate in the billions. The non-daemon path already carries the previous oldvalue forward; this matches it. Refs #785 Signed-off-by: Thomas Vincent <thomasvincent@gmail.com> * test: follow Cacti's test layout and composer scripts Adopts the conventions from Cacti core: tests/bootstrap-unit.php, tests/Helpers for the stubs, a phpunit.xml carrying error_reporting -1 and CACTI_TEST_BOOTSTRAP, and composer lint / test / test:coverage scripts so CI runs the same commands a developer does. The dev toolchain is Cacti's, pinned to the same platform php 8.1.0. Cacti core runs Pest and this suite does not, because pest ^2 does not resolve on PHP 8.1 -- the platform Cacti's own composer.json pins. Releases up to v2.36.0 conflict with phpunit 10.5.62 and later, every earlier 10.x release is blocked by advisory PKSA-z3gr-8qht-p93v, and v2.36.1, which does resolve, requires PHP 8.2. The stack installs on 8.2 and above; 8.1 is the floor this plugin's CI matrix targets. The tests are written in the plain PHPUnit class style that Cacti's tests/Pest.php explicitly supports, so they run unchanged under Pest wherever it is installable. Signed-off-by: Thomas Vincent <thomasvincent@gmail.com> * ci: keep plugin PR integration checks on pinned Cacti * fix(counter): handle non-integer 64-bit readings safely * ci: bound package index refreshes --------- Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
30 lines
1.3 KiB
Docker
30 lines
1.3 KiB
Docker
# Test runner for the Thold plugin.
|
|
#
|
|
# Pinned to PHP 8.1 because that is the oldest interpreter the CI matrix
|
|
# covers; what passes here passes on 8.2-8.4. pcov rather than Xdebug: line
|
|
# coverage is the only debug feature the suite needs and pcov is far cheaper.
|
|
FROM php:8.1-cli-alpine@sha256:7949370448b0b4d9787776dc5968e0fd8d48763292344b5fbf21539441228a98
|
|
|
|
# git is needed by the changed-line coverage gate, which diffs against the
|
|
# base branch.
|
|
RUN apk add --no-cache git gmp-dev \
|
|
&& docker-php-ext-install gmp \
|
|
&& apk add --no-cache --virtual .build-deps $PHPIZE_DEPS \
|
|
&& pecl install pcov \
|
|
&& docker-php-ext-enable pcov \
|
|
&& apk del .build-deps
|
|
|
|
COPY --from=composer:2@sha256:4d71c3c2109c61d5415544264b59ad4087e4c5b7244481723664138fd36d5040 /usr/bin/composer /usr/bin/composer
|
|
|
|
# The plugin lives where Cacti would put it, because thold_functions.php
|
|
# resolves its own includes through $config['base_path'] . '/plugins/thold'.
|
|
# No network or database is involved; the Cacti framework functions themselves
|
|
# are stubbed in tests/bootstrap.php.
|
|
WORKDIR /cacti/plugins/thold
|
|
|
|
ENV COMPOSER_ALLOW_SUPERUSER=1 \
|
|
COMPOSER_NO_INTERACTION=1 \
|
|
COMPOSER_CACHE_DIR=/tmp/composer-cache
|
|
|
|
CMD ["sh", "-c", "composer install --no-progress --no-ansi && composer test"]
|