Ahoi controller-dev and others who may have an idea (please + anyone else
applicable),

How do you write an AbstractDataBrokerTest and in it wait for a put on the
DataBroker to have processed by all of its registered
DataTreeChangeListener ?

Background with concrete example: The (Abstract)AclServiceTest  in
https://git.opendaylight.org/gerrit/#/c/42109/ (see [1]) puts two entries
into the DataBroker, the 2nd of which triggers a DataTreeChangeListener
which ultimately calls some service. The test asserts that this service got
called (slightly simplified, but that's the gist of that test).

I've inserted a Thread.sleep(500) after the DataBroker put and before the
assert, to give the DataTreeChangeListener a chance - I understand runs
asynchronously, right?

This sleep makes that test work just fine (contrary to without any sleep,
when it fails, but just sometimes; that's always fun) - but I'm wondering
if there would be better way to write these kind of tests, without sleep
... but not quite clear in my mind yet how.

I've written tests like this before, using e.g.
https://github.com/awaitility/awaitility, which is just a nice utility to
poll say every 100ms for max. 2s for a certain condition to be true - but
what is that condition in this scenario - what API / helper would one use
to ask a DataBroker "have all of your listeners already processed all of
your pending puts" ? If this is impossible as is today, would this seem
like a fair enhancement request - would you consider adding something like
this, specifically to aid in writing tests?

[1] (Abstract)AclServiceTest is an AbstractDataBrokerTest, even if it
doesn't extend AbstractDataBrokerTest; ignore that, it's just because of
https://git.opendaylight.org/gerrit/#/c/43645/

Thanks a lot,
M.
--
Michael Vorburger <vorbur...@redhat.com> | IRC: vorburger @freenode | ~ =
http://vorburger.ch
_______________________________________________
controller-dev mailing list
controller-dev@lists.opendaylight.org
https://lists.opendaylight.org/mailman/listinfo/controller-dev

Reply via email to