-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ensure Backend’s messages stay translated #1166
Ensure Backend’s messages stay translated #1166
Conversation
0a5799e
to
5fe2a89
Compare
BEGIN { use_ok 'Zonemaster::Backend::Translator'; } | ||
|
||
isa_ok 'Zonemaster::Backend::Translator', 'Zonemaster::Engine::Translator'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it be better to move the use_ok and isa_ok checks to 00-load.t and simply use Zonemaster::Backend::Translator
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I disagree. It’s customary to have a BEGIN { use_ok 'SomeModule' }
in a unit test for a module. And the isa_ok
assertion ensures that Zonemaster::Backend::Translator
is a subclass of Zonemaster::Engine::Translator
. These are all properties about the Zonemaster::Backend::Translator
module I want to test, so I think it makes sense to keep them here.
Also, it isn’t clear what t/00-load.t
is supposed to do. It seems like it is some kind of basic smoke test. It’s probably better left as it is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I don't like about use_ok
is that it doesn't abort on failure, which IMHO is the reasonable thing to do. Instead it continues executing until it inevitably crashes and prints additional error output for no good reason. I admit this nothing more than a nuisance.
I understand t/00-test.t
to be a simple smoke test that just verifies that all module can be loaded without error. If you have good test coverage this is redundant in a sense, but it's also fast and low effort to maintain. And this can be valuable if the rest of the test suite is slow.
With that I rest my case.
The unit tests suite of Zonemaster::Backend did not test the Translator module directly. Despite Devel::Cover already reporting good coverage of Zonemaster::Backend::Translator, no unit test really looked at the operation or the output of that module’s methods. This causes subtle regressions in Zonemaster::Engine::Translator, for example, to slip by unnoticed. When running the new t/translator.t script, a handful of tests will likely fail if the corresponding fixes for Zonemaster::Engine::Translator aren’t merged yet.
The recent case alteration of module names has caused messages whose module attribute is BACKEND_TEST_AGENT to be stored as Backend_Test_Agent instead. The database migration script for version 11.0 took care of that, but the rest of the code had not been adjusted accordingly. This meant that the Backend-specific TEST_DIED or UNABLE_TO_FINISH_TEST tags were no longer translated appropriately. In the meantime, new tests run on the backend will still store BACKEND_TEST_AGENT instead of Backend_Test_Agent. To fix this inconsistency, a change needs to be done to Zonemaster::Backend::DB and a migration script needs to be written to fix the entries generated with the backend between version 11.0 and the next release.
The recent case alteration of module names has caused messages whose module attribute is BACKEND_TEST_AGENT to be stored as Backend_Test_Agent instead. However, new tests run on the backend still store the module name as BACKEND_TEST_AGENT instead of Backend_Test_Agent. This commit fixes the inconsistency by ensuring that new tests store the correct module name. Now, we still need a migration script to fix the entries generated by the backend between version 11.0 and the next release.
With the previous changes, “BACKEND_TEST_AGENT” should have been stored as “Backend_Test_Agent” in the database. This migration script ensures everything is consistent again.
The clean way of invoking a parent’s method in a class that overrides that method is to use the SUPER pseudo-class, instead of repeating the name of the parent class. Details are in the “perlobj” manual page.
For messages generated by the backend, store them as the “Backend” module instead of “Backend_Test_Agent”. The use of mixed case with underscores is unsatisfactory and the test agent is the only place in the backend that generates these messages. In essence, “Backend” could be a synonym for “System”, but it’s better to keep the Engine’s system messages separate from the Backend’s.
7ab6203
to
2e0e172
Compare
Pull request zonemaster-engine#1347 (zonemaster/zonemaster-engine#1347) has been merged, which fixes Zonemaster::Backend::Translator->instance(). So we can remove one use of the deprecated Zonemaster::Backend::Translator->new() in the unit tests.
@marc-vanderwal, |
Tested and working on Ubuntu 20.04.6 and 22.04.4. Bug:on Ubuntu 20.04 the migration script in
Commenting the line make the migration script work. Test Procedure:
|
Oh, I see. We don’t need |
Changes tagging of this from |
Purpose
This PR adds unit tests for
Zonemaster::Backend::Translator
and addresses an oversight in Backend caused by storing the module’s names as mixed case instead of uppercase.Context
Submitting PR zonemaster/zonemaster-engine#1346 made it clear that
Zonemaster::Backend::Translator
lacked appropriate unit tests. When adding them, I found more bugs, now addressed in the same PR. I also noticed that all Backend-generated messages suddenly became untranslated.Changes
Backend_Test_Agent
;How to test this PR
Prerequisite: PR zonemaster/zonemaster-engine#1346 must be merged beforehand in Zonemaster-Engine. Alternatively, install a local copy Zonemaster-Engine from a local development branch with this PR merged. If not, one of the newly-added unit tests will fail.
Before merging this PR locally: run a test on a domain name that causes Zonemaster to time out, such as
pool.ntp.org
, usingzmtest
. Note the test ID. Wait for the test to time out. Notice that the UNABLE_TO_FINISH_TEST message is untranslated (i.e., only the message tag is visible).After merging this PR locally: run the unit tests. Ideally, make sure that the tests in
t/translator.t
have been executed.Run the database migration script. Then use
zmb get_test_results --test-id $TEST_ID
where$TEST_ID
is the test ID ofpool.ntp.org
that was run before merging the PR locally. Expect the UNABLE_TO_FINISH_TEST message to be translated.Run the same test again on
pool.ntp.org
usingzmtest
; wait for it to time out. Expect the UNABLE_TO_FINISH_TEST message to be translated as well.