kaocha

Official support channel: https://clojureverse.org/c/projects/kaocha
plexus 2020-12-04T09:03:39.195100Z

I'll see if I can have a poke at this over the weekend. I would try doing the retries immediately inside wrap-run.

2020-12-04T09:37:17.195500Z

ah yeah I thought about moving everything inside wrap-run

2020-12-04T09:37:57.196300Z

I can try that

2020-12-04T09:39:11.197200Z

so you think I can just do everything with only wrap-run right?

2020-12-04T09:40:45.199100Z

so the thing I don't get is that I would have thought that wrap-runwould only run once, but it seems like it runs multiple times

plexus 2020-12-04T09:40:46.199500Z

I think so, I think that'll be the easiest path, since that way from the test type implementation's perspective it's all part of executing a single test. What you do now, calling run-testable inside post-test is going to cause some weird nesting, that might cause issues

2020-12-04T09:42:01.201100Z

yeah I noticed some weird interactions between my wrap-run and my post-test, even if the retries atom was modified if I only override post-test, I don't see the changes when I had both enabled

plexus 2020-12-04T09:42:15.201500Z

that is strange, it should run once for the test plan

plexus 2020-12-04T09:42:25.201800Z

(defn ^:no-gen run
  "Given a test-plan, perform the tests, returning the test results.

  Also performs validation, and lazy loading of the testable type's
  implementation."
  [testable test-plan]
  (load-type+validate testable)
  (binding [*current-testable* testable]
    (let [run (plugin/run-hook :kaocha.hooks/wrap-run -run test-plan)

plexus 2020-12-04T09:42:44.202500Z

uh wait no, that's probably not true

2020-12-04T09:42:47.202700Z

I'll check again but I was quite surprised as well, with a debugger on it was entering wrap-run 2/3 times even with a single run

plexus 2020-12-04T09:43:34.203400Z

ok, the docs are wrong, that run is called for each testable, so yes wrap-run is called for each testable

plexus 2020-12-04T09:44:02.203700Z

oh... one sec let me check something

plexus 2020-12-04T09:45:17.204800Z

ok, I was confusing two different things, there's the wrap-run hook, this wraps kaocha.testable/run, so in other words it wraps on the "outside" of the test type implementations

plexus 2020-12-04T09:45:36.205300Z

there's also :kaocha.testable/wrap, which you can set on a testable, and this will be called inisde the test type implementation

plexus 2020-12-04T09:46:39.206200Z

you'll have better luck with that one

(pre-test [testable test-plan]
  (update testable :kaocha.testable/wrap conj (fn [run] (fn [] ... (run) ...))))

plexus 2020-12-04T09:46:54.206400Z

sorry for putting you on the wrong path!

plexus 2020-12-04T09:48:24.207500Z

I can code up an example over the weekend if you like, this really wraps on the lowest level, i.e. executing the test var itself, so if you do your retries in there then from the point of view of the rest of kaocha it still looks like a single test.

2020-12-04T09:49:18.208200Z

ah nice, and sure if you could make up an example it would be great, I can also try something out now with this approach

2020-12-04T09:49:24.208700Z

which seems more promising

plexus 2020-12-04T09:49:24.208900Z

(which I think is what you would want)

2020-12-04T09:49:45.209700Z

and yeah it should look like a single test, however I should still track how many times it retried

2020-12-04T09:49:55.210100Z

but I can do that with an atom or appending something to testable I guess

plexus 2020-12-04T09:50:28.210800Z

I'm not sure if all of our test type implementations honor :kaocha.testable/wrap, would have to check, most probably do. I'm also not sure if it's documented 🙈

plexus 2020-12-04T09:51:00.211500Z

yeah just stick whatever tracking atoms you need onto the testable, or close over them in your wrapping function, you should be able to keep your state pretty localized

2020-12-04T09:51:11.211900Z

it's mentioned on the extending doc

plexus 2020-12-04T09:51:23.212200Z

note that it's :kaocha.testable/wrap, not :testable/wrap like I said before

2020-12-04T09:51:50.212500Z

yeah I can see it used in the capture output plugin

1
2020-12-04T10:30:15.213800Z

it retries as expected at least,but the reporting is still not right

2020-12-04T10:30:27.214400Z

do I still need to with-redefs the report function?

2020-12-04T10:37:54.214900Z

yeah I think the counters get confused as well

2 tests, 4 assertions, 2 failures.
#:kaocha.result{:count 2, :pass 2, :error 0, :fail 2, :pending 0}

2020-12-04T10:38:19.215400Z

there were only two test, and one test failed twice and then worked

2020-12-04T10:38:53.216Z

but yeah probably the counter is not a big issue, reporting the test as failed is more the problem

plexus 2020-12-04T10:45:06.217600Z

yes, you'll still have to with-redefs the reporter, because you only want to actually report the events from the last retry. For the record counters have a look at the with-report-counters macro

plexus 2020-12-04T10:46:34.218700Z

not to use directly but to see what's involved, I think if you can capture t/*report-counters*, then reset them to their initial value each time you restart the test

2020-12-04T10:53:46.219Z

nice amazing think it all works now

2020-12-04T10:53:56.219400Z

apart from the counters but maybe I'll leave them like that

2020-12-04T10:54:03.219700Z

to make it more explicit

2020-12-04T10:54:33.220300Z

ah no wait the counters seem to be fine as well now that I capture the report

plexus 2020-12-04T12:17:16.220800Z

ah that's great, I thought that might be the case but wasn't sure. Looking forward to your plugin, i think a lot of people will find this useful!

2020-12-04T13:49:44.221400Z

yeah it's published https://clojars.org/kaocha-retry-plugin and the code is: https://github.com/AndreaCrotti/kaocha-retry

2020-12-04T13:50:11.222300Z

however I'm not sure it's following best practices atm, but I think it's definitively usable already

2020-12-04T13:50:40.223100Z

one question, should you generally make a plugin do something just because it's added to the list of plugins?

2020-12-04T13:50:50.223500Z

or is better to still keep it disabled by default?

2020-12-04T13:51:36.224500Z

and also the plugins list is supposed to be just used globally in tests.edn or it makes sense to set a different plugin list for each test scenario?

plexus 2020-12-04T14:07:13.228100Z

Oh no you did the thing I asked you not to do... Please be mindful of naming! This is not an official Kaocha plugin so it should not be in a kaocha.* namespace. Artifact names without a prefix is also discouraged nowadays. Sorry I should've spotted this earlier but it's also explicitly mentioned in the docs for extending Kaocha.

plexus 2020-12-04T14:09:35.229700Z

Having a plug-in just do something when enabled isn't necessarily a problem, but it's a nice courtesy to also have a config flag for instance to change it based on the profile.

2020-12-04T14:15:42.230500Z

yeah sorry I'll change the name, I kind of knew it wasn't a good idea but I wasn't sure what to call it

2020-12-04T14:17:18.231100Z

the actual project on github and clojars is fine though right?

2020-12-04T15:04:17.234Z

actually I was trying to make the retry disabled by default, and enabling it with something like:

:tests [{:id                  :unit
          :retry.plugin/retry? true
          :test-paths          ["test"]}]}
however that config will be reachable in testable, but only in the :unit testable (which makes sense I guess). But can I access that config variable from the leaf testable as well?
(pre-test [testable test-plan]
    (let [max-retries (::retry-max-tries test-plan 3)
          wait-time (::retry-wait-time test-plan default-wait-time)
          retry? (::retry? testable false)
          test-id (:kaocha.testable/id testable)]

plexus 2020-12-04T15:16:12.235300Z

does it have to be on the test suite level? or can it be at the top level? you have access to the test-plan (i.e. the top level config), and to the current testable. If you want something in between (in this case two levels up), you would have to scan the hierarchy from the test-plan, based on the current testable.

plexus 2020-12-04T15:20:44.238600Z

regarding naming, both namespaces and artifacts (jars) use reverse domain name notation, to ensure that things are globally unique. That's not very strictly adhered to in the clojure world, but my philosophy is that the first one or two segments should be something you fairly uniquely "own". All our namespaces start with either lambdaisland or kaocha, we claim those names, and I don't expect anyone else to put stuff out under those names. retry is very generic, you can't really claim that, so I don't think it's a great first segment. if you have a personal domain you can use that, com.andreacrotti/kaocha-retry or something like that. Some people also use something like github-andreacrotti/kaocha-retry

2020-12-04T15:36:19.239700Z

ah ok yeah I thought that setting the group-id with this little tool https://github.com/applied-science/deps-library#usage was enough to set the namespace, but yeah I'll change it to andreacrotti/kaocha-retry maybe

2
2020-12-04T15:36:48.239900Z

yeah I think I'd like to make it easy to enable per test scenario

2020-12-04T15:37:04.240100Z

and ok I can try to scan the hierarchy then

2020-12-04T15:37:32.240300Z

I think the idea is to not retry all the tests, since in theory retrying could be considered a bad thing