chore: addmailuser - Remove delaying completion until /var/mail is ready#2729
Conversation
This was apparently only for supporting tests that need to wait on account creation being ready to test against. As per the removed inline docs, it should be fine to remove once tests are updated to work correctly without it.
`wait_until_account_maildir_exists()` provides the same logic `addmailuser` command was carrying, to wait upon the account dir creation in `/var/mail`. As this was specifically to support tests, it makes more sense as a test method. `add_mail_account_then_wait_until_ready()` was added to handle the common pattern of creating account and waiting on it. An internal assert will ensure the account was successfully created first during the test before attempting to wait.
…essed The current helper is more complicated for no real benefit, it only detects when a change is made that would trigger a change event in the `changedetector` service. Our usage of this in tests however is only interested in waiting out the completion of the change event. Remove unnecessary change event waits. These waits should not be necessary if handled correctly.
The method is unaltered, just repositioned.
`wait_until_account_maildir_exists` was added to ensure the account is ready in two tests. Some blank lines were added/removed for consistency.
This helper method is used where appropriate. - A password is not relevant (optional). - We need to wait on the creation on the account (Dovecot and `/var/mail` directory).
The delete test was failing as the `/var/mail` directory did not yet exist. There is now a proper delay imposed in the `add` test now shares the same account for both `update` and `del` tests resolving that failure. Additionally tests use better asserts where appropriate and the wait + sleep logic in `add` has been improved (now takes 10 seconds to complete, approx half the time than before). The `del` test TODO while not technically addressed is no longer relevant due to the tests being switched to `-c` option (there is a separate `no container` test file, but it doesn't provide a `del` test).
This comment was marked as resolved.
This comment was marked as resolved.
This test helper relies on a `debug` log output by `check-for-changes.sh`. Additionally `setup-cli.bats` was not using it properly as the container name wasn't passed as an arg.. and no failure was raised.
7eaf142 to
2e3716a
Compare
`/etc/dms-settings` quote wraps the value, but the assert wasn't helpful either with the failure (no match). Chose to fetch the ENV from container environment with `env` as we don't rely on `start-mailserver.sh` processing for this ENV anyway. Also switched to `assert_regex` for better failure output. The `changedetector` state conditions were returning the wrong status code (0 is true/ok in bash). An earlier misunderstanding to resolve a failure had me add explicit status codes to return for true/false, as it didn't seem to work correctly with just the `[[ expression ]]` but was due to something else?
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
georglauterbach
left a comment
There was a problem hiding this comment.
Had a look again, got a nice overview with your comments, and this looks good - LGTM 👍🏼
This comment was marked as resolved.
This comment was marked as resolved.
There is not much reason to check before waiting on ClamAV. It is more helpful to debug failures from `nc` mail send commands if we know that nothing went wrong inbetween the ClamAV wait time. Additionally added an assertion which should provide more information if this part of the test setup fails again.
fecfe6d
Healthcheck test failure investigation (fixed)Well it didn't fail at the same spot, this time it was the healthcheck test: docker-mailserver/test/tests.bats Lines 974 to 978 in 26d2413 docker-mailserver/test/tests.bats Line 40 in 26d2413 That's fairly far down in the test, not sure how it ended up unhealthy?
Defaults: I think |
This test is a bit fragile. It relies on defaults for the healthcheck with intervals of 30 seconds. If the check occurs while Postfix is down due a change event from earlier tests and the healthcheck kicks in at that point, then if there is not enough time to refresh the health status from `unhealthy`, the test will fail with a false-positive as Postfix is actually working and up again..
|
I hope I got this right: as the new |
Before / After (verbose)Before:
Now:
So mostly, Neither guarantees Dovecot or Postfix is up, as v12 can change from New race condition failure - `email del -y` (resolved)New transient failure (this PR is just the gift that keeps on giving with random failing tests..): This time it's a test this PR actually touches, and is enabling a check that was previously disabled: # Mail storage for account was actually removed by `-y`:
run docker exec "${TEST_NAME}" ls /var/mail/example.com/user
assert_failurePotentially a race condition with the previous This is perhaps one of those scenarios where proper locking with
|
Workaround that tries not to introduce heavier delays by waiting on a full change event to complete in the previous `email update` if possible. There is a chance that the account has the folder deleted, but restored from an active change event (for password update, then the account delete). --- Additionally apply review feedback to add inline maintainer note about the healthcheck test to avoid refactors making the same mistake.
Description
Quick Summary
Resolves a
TODOtask withaddmailuser.Overview
The main change is adding three new methods in
common.bash, which replace the completion delay inaddmailuser/setup email addcommand.Other than that:
sh -c 'addmailuser ...'tosetup email add ....setup-cli.batsforsetup email add|update|del(logic remains effectively the same still).TODOcomment forsetup-cli.batstest onsetup email delto better clarify the concern, but the test itself was no longer affected due to changes prior to this PR, so I enabled the commented out assertion.skiptests intest/tests.batscould be enabled again after this PR.Commit messages provide additional details if helpful.
Details
Presently when adding a user to
postfix-accounts.cfwith a running container, theaddmailuser(akasetup email add) command will delay completion until the account has a directory in/var/mail(which is created by thechangedetectorservice during creation of the Dovecot user).AFAIK the delay was added primarily for our test suite and serves no other purpose. This PR migrates that delay logic into
common.bashtest helper methods, resolving theTODO.Future work
A future improvement might instead skip the
changedetectorservice and add the Dovecot account directly.Presently that is not an option as that functionality is wrapped in a loop and assumes a clean slate.
The upcoming Dovecot
mailcryptplugin feature does requireaddmailuserdelaying until/var/mailaccount folder is available however. This PR will not help users of that feature until Dovecot accounts can be created directly without relying onchangedetector.TODO addressed by this PR
Removed comment inline-docs
TODOfor reference (and having Github link the PR to those issues if traceability is needed in future)Fixes: #2096 (comment)
Type of change
Checklist: