Testing a rule
Before enabling a rule, it is worth testing it — to see exactly which ads would be affected. For this, the rule editor has a Test tab: it runs your code on the current live ads on the server and shows the result. During the test nothing is paused and no commands are sent to Facebook — but requests from the rule code to external addresses (fetch) are real: they go out to the hosts on the allowlist.
How to test a rule
-
Open a rule in the editor (or create a new one) and write the code. Read more — Creating a rule.
-
On the right, switch to the Test tab and click Test on live data. The tab is shown only to roles that are allowed to manage rules; everyone else sees only the Macros tab. Under the button a permanent note says: External requests work only for allowed addresses.

Britva will first check the code the same way as on save, then load the ads visible to you and run your code on them. If the code shape is wrong, the run does not start: the Test failed pop-up message names the reason in the same words as on save (see If a rule does not save).
-
Look at the result. The panel is headed Test results. At the top — a counter … / … matched (the numbers stand in place of the ellipses): how many ads would be affected by the rule out of the total checked; if the rule makes
sqlqueries, next to it you see Database queries: … (the number of queries stands in place of the ellipsis) — how many of those queries went out during the run. Below — the list of these ads: their ID, geo, name and which action would trigger (for example,pause ad=... 24h). If no ad matched, the list is replaced with No ads matched this rule. -
Having corrected the code, click Re-run to run the test again.
How to read the result
- The list of matches — ads for which the rule would call an action. Next to each — an action label (pause/activate, level and duration). The reason is shown in the label's tooltip on hover. If there are very many matches, the list shows the first of them and a line below says how many are hidden; the "N / M matched" counter still counts every matched ad.
- Messages from the code — if the rule has console output (
console.log(...)), these lines are shown under the ads the rule would act on. Handy for debugging: you can output intermediate values and see how the rule reached its decision. The output is visible only here: the real cycle does not save it. Very large and very deeply nested values are shown shortened — with the marks[Object],[Array],[Circular], or with the size instead of a string that is too long. - Errors — if the rule ended with an error on some ads (for example, by accessing a non-existent field), a red warning appears at the top: … ads errored. (the number of such ads stands in place of the ellipsis). When there are several of them, the line goes on with First: and the text of the first error. Three cases are also named in words, and the error text stays under them on its own line: The rule ran too long and was stopped. — the rule did not fit into its time limit (see Rule time limit); The pattern match could not be completed — the match was not decided. — a search by a regular expression could not be completed, so it is unknown whether it matched; The rule exceeded the memory limit and was stopped. — the rule went over the memory limit set by the Memory per script field (see JavaScript). The error text shows which limit was not met. Fix the code and run the test again.
- Incomplete run — the whole check has an overall time limit: an administrator sets it with the Test: overall run deadline, ms setting of the "Britva rule engine" job (the Services and jobs section, see Services and jobs). When it runs out, the walk over the ads stops, and a warning appears above the result: Run stopped on the time limit: … of … ads checked. The result is incomplete — simplify the rule and run it again. — the first number is how many ads were checked, the second is the total. If the rule got stuck in a built-in operation and did not finish even after its own time limit, the walk stops at once: Run stopped: a rule would not finish and was abandoned. … of … ads checked. The result is incomplete — simplify the rule and run it again. — the numbers mean the same. In both cases the match counter counts only the ads that were checked.
Test a rule before enabling it. A convenient order: save the rule disabled, run it on the Test tab, make sure the matches include exactly the ads you expected — and only then enable it.
The rule's own memory (ctx.state) starts empty on every test run and is not saved. The shared store (ctx.state.global) can be read in the test, but writing to it is refused — the test never changes shared data.
If ctx.state.set() refused a value that cannot be saved (see What state can store) and the error was not caught, the ad goes into the count of ads with an error, and there is no decision for it.
The test works with the same limits as the working cycle: one ad gets the same time limit, and the number of fetch calls is limited for the whole test run the same way as for one pass of the working cycle (fetch: max calls per tick). The test goes over the ads visible to you, and its sql queries run within your rights. One addition the working cycle has no need of: the answer carries a bounded number of action rows, so when a rule matches very many ads the list is cut as described above — the walk itself still covers every ad.