Skip to content

Commit 10b3fa5

Browse files
test: add retries to pf rule reads for dnpipe limiter check
1 parent 91afb63 commit 10b3fa5

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Tests/APIModelsFirewallRuleTestCase.inc

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ use RESTAPI\Responses\ServerError;
1616
class APIModelsFirewallRuleTestCase extends TestCase {
1717
/**
1818
* Reads the active ruleset directly from pfctl.
19+
* @param string|null $needle If provided, ensures this string is found in the pfctl output before returning.
20+
* @return Command The Command object containing the pfctl output.
1921
*/
20-
public function read_pfctl_rules(): Command {
22+
public function read_pfctl_rules(?string $needle = null): Command {
2123
# Keywords that indicate pf is not ready yet
2224
$not_ready_keywords = ['pfctl: DIOCGETRULE: Device busy', 'pfctl: DIOCGETRULENV: Device busy'];
2325

@@ -28,9 +30,9 @@ class APIModelsFirewallRuleTestCase extends TestCase {
2830
$cmd = new Command('/sbin/pfctl -sr');
2931
$ready = true;
3032

31-
foreach ($not_ready_keywords as $keyword) {
33+
foreach ($not_ready_keywords as $kw) {
3234
# pf is not ready if any of the keywords are found in the output
33-
if (str_contains($cmd->output, $keyword)) {
35+
if (str_contains($cmd->output, $kw) or ($needle and !str_contains($cmd->output, $needle))) {
3436
$ready = false;
3537
$attempt++;
3638
sleep(1);
@@ -833,7 +835,7 @@ class APIModelsFirewallRuleTestCase extends TestCase {
833835
$rule->create(apply: true);
834836

835837
# Ensure the dnpipe is correctly represented
836-
$pfctl = $this->read_pfctl_rules();
838+
$pfctl = $this->read_pfctl_rules(needle: $rule->tracker->value);
837839
$this->assert_str_contains(
838840
$pfctl->output,
839841
"ridentifier {$rule->tracker->value} dnpipe {$limiter->number->value}",

0 commit comments

Comments
 (0)