Closed (fixed)
Project:
Scheduler
Version:
8.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
1 Dec 2015 at 12:32 UTC
Updated:
9 Mar 2016 at 14:50 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
jonathan1055 commentedHi chr.fritsch,
Thanks for the patch. I'll test it.
We were already aware that this task was still remaining and the original issue was #2432341: Convert 'scheduler/cron' to a route controller. Normally we'd close the newer one and mark it as dupliacte of the earlier issue, but seeing as you have provided a patch here and there was none on that issue I will keep this newer one open.
Jonathan
Comment #3
jonathan1055 commentedI've applied the patch and scheduler/cron is working but only if I create a lightweight key. Was it your intention to force this? Looking at the code, if both the stored key in the settings and the passed url element are blank then it should still pass?
Also my cron jobs do not seem to appear everytime in the log. I had a task set for */3 and it ran once sucessfully but will not run again. Neither do I get the 'access denied' message. I'm not sure what is going on there.
I'd like Pieter to review your patches too, as he has more experience than me or D8 route controllers, etc.
But thanks for getting this started, and certainly I did see a lightweight cron run, so it is working of sorts.
Comment #4
jonathan1055 commentedI have just looked back and Pieter already asked the question about making the cron access key mandatory in comment 46 of #1982932: Drupal 8 Port of the Scheduler Module. Having thought about it, we should take this opportunity to enforce the key and not allow runs from unauthorised users (even though we discussed on 7.x that this would not pose any real problem).
So now we just need to understand exactly how the current patch is forcing an access key, as it is not clear why this is the case.
Comment #6
jonathan1055 commentedUpdated summary, taken from #2432341: Convert 'scheduler/cron' to a route controller which is closed as a duplicate
Comment #8
polynya commentedHere is an updated patch. I have made a few small changes:
no_cache: TRUEto the route to ensure the job always runs.Comment #9
polynya commentedThe reason that the original patch forces a key to be used is that
cron_key: ''was not added to the route. See this example.Comment #10
jonathan1055 commentedHi polynya,
Thanks for re-rolling this patch, I can see you had to do a bit of work as the patch in #1 was out of date.
You've added quotes around all the strings in .routing.yml, I presume that's the standard? Thanks for explaining why the previous patch forced a cron_key. Nice catch to make the form field required.
I have tested the change and it all seems to be working perfectly. My observations:
Response('', 204)instead ofRedirectResponse('/')that the previous patch had. I'm ok with this if this is the right way to do it, but I'd like my other co-maintaniner to give an opinion too._scheduler_cron_access($cron_key)in .module is now redundant and can also be removedI've re-rolled the patch, with all your changes exactly as in #8 but also removing _scheduler_cron_access and altering the help text.
ps. I changed the issue title simply because we have many issues starting 'Convert ...' and with many tabs open in a browser only showing the first word of the page title they all look the same.
Comment #11
polynya commentedHi Jonathan,
Thanks for responding so quickly. I've applied your new patch and get the same results for tests 1-5. Test 5 returns no content (HTTP 204), which I think is the correct response, but I'm OK if you want to change it back.
I haven't found YML files in the Drupal coding standards but there's this reference. I've just copied the format from core modules.
Adrian.
Comment #12
polynya commentedI found an issue on the cron settings form. When the module is enabled, the lightweight_cron_access_key setting is empty. It's not possible to run 'Generate new random key' on the form because the lightweight_access_key field is required but is empty.
I have got round this by setting lightweight_cron_access_key to a random value in scheduler_install(). This is better for security anyway.
I've re-rolled the patch. The only change from patch 10 is in scheduler.install.
Comment #13
jonathan1055 commentedGood catch. Tested and it works nicely.
Re-rolled with a comment added in hook_install() and a simplification of the help text now that the key is guaranteed to exist.
Do you think we need to add automated tests for this functionality? Once we've written it, it is unlikely to change and go wrong. Can we assume the route controller will always work? Do we need to check access is denied without the correct cron key? I don't want to spend effort on writing tests which are never going to trap any future fault. On the other hand, if we'd had tests for scheduler/cron in 7.x we would have discovered this omission earlier.
Comment #15
polynya commentedHere's a new patch with some tests for lightweight cron. Do you think we need any more tests?
Comment #16
chr.fritschComment #17
jonathan1055 commentedGreat, thanks for the test file. I've noticed a few things which need to be changed (problem with 'locale' and the wrong cron urls), but I have uploaded a patch of just the tests from #15 above onto issue #2594615-152: Automated testing in 8.x [meta] to see how it runs as-is.
Comment #18
jonathan1055 commentedHere's a re-roll to contain just the new test file, with the following changes:
cronwhere they should bescheduler/cron$key = $key_xpath[0];is not empty - see debug outputThe number of fails should be more than the 2 fails previously on https://www.drupal.org/pift-ci-job/164188
Comment #20
jonathan1055 commentedThe patch in #18 looked OK to me. Seems there was a testbot CLI error. Going to re-test and see if runs this time.
Comment #21
jonathan1055 commentedHere's the error text I forgot to add in #18. I cannot see any reason to add 'locale'.
Comment #24
polynya commentedThanks for reviewing the test. I had added the 'locale' module because it prevents the error you reported in #21. I don't know what causes the error but it only occurs for me when running the test through the UI (admin/config/development/testing). It doesn't occur when using run-tests.sh.
You tried running the test file on its own on Convert tests. It failed because it depends on the key being set when the module is enabled, which is in the full patch for this issue.
I have re-rolled the patch with your changes to the test file and minor changes from me.
Comment #25
polynya commentedComment #26
jonathan1055 commentedThat is strange, because I was getting completly the opposite! I got the error with locale added, and the error disappeared when I took 'locale' out of the list.
Yes, exactly. That is what I wanted to show - how the tests perform without any fixes to the route code. You have to show the tests failing so that when the fix is applied and you get greens you know that the change has made a difference. It highlighted the problem with the check empty($key) returning false even when there was no value, ie a test was passing when it should have failed. From a quick glance at your new patch it looks like you have addressed this. I will test it fully and if running OK will commit the test file on its own first. Then we get the branch test results before the code fix is committed.
Thanks very much for your work on this.
Comment #28
jonathan1055 commentedHere is just the test file from 24, i.e. running without the code fixes.
Comment #30
jonathan1055 commentedThree tests fail here:
The test "Lightweight cron key field is not empty by default." does not fail but it should do. The object is not empty (which is correct) so testing !empty() on the XMLElement object does not give what we want. It should actually be testing the value, which is empty. Casting as string fixes this.
I have also added two more checks - to make sure we get the validation message 'cron key is required' and also that the form cannot be saved. With these extra two tests, plus the fix above there should be six fails.
Comment #32
jonathan1055 commentedsix fails as expected:
Comment #34
jonathan1055 commentedThe tests are committed.
Here is a patch for the code fixes. Should get a clean set of passes for this class.
Comment #36
jonathan1055 commentedGood.
and in the dispatcher:
Comment #38
jonathan1055 commentedCommitted and fixed.
Thanks very much Adrian (polynya) and Christian (chr.fritsch) for your work on this. You are welcome to take a look at our other issues currently blocking the first 8.x release #2662476: Progress towards 8.x release of Scheduler - your help would be appreciated :-)
Comment #42
jonathan1055 commentedIgnore the failed patches above. They were queued but not run until the 8.x committed codebase passed all tests. That happened with my commit a few minutes ago, and then the untested patches have suddenly come to life and been run. This issue is already fixed and closed.