On Sun, Dec 11, 2011 at 6:48 PM, Lance Norskog <goks...@gmail.com> wrote:

> What about using ThreadLocal generators?
>
> On Sun, Dec 11, 2011 at 11:42 AM, Sean Owen <sro...@gmail.com> wrote:
> > On Sun, Dec 11, 2011 at 7:35 PM, Ted Dunning <ted.dunn...@gmail.com>
> wrote:
> >
> >> The right way to handle this is to have instances get a random number
> >> generator that works like it should.  Magic resets in the middle of
> >> operation are not a good idea.
> >>
> >
> > Why would the caller care? It's all random numbers, whether "reset" or
> not.
>

The care is about determinism.

Tests are easier if they produce the same result every time.  Some tests
are probabilistic in nature and thus can't be guaranteed to pass every time
without making them so lax as to be not useful.  By making them
deterministic, they become regression tests rather than tests in principle,
but also become more useful in general.


>> I think we need a better way to inject generators that doesn't involve
>> statics.
>>
>>
> There is no way to control and reset Randoms other than what's done in
> RandomWrapper (with statics). If you think deterministic tests are a good
> goal, there's no argument with this, as it's the only way to do it. (And
if
> you don't agree that's another conversation -- but we do need this.)
>
> To be clear: the injection is not at all the issue here. I'm happy to
write
> an essay on this, but, the punchline is: there is virtually no way to have
> deterministic tests in one JVM while running all the tests in parallel.

This is just simply not true.

You absolutely can have deterministic and independent generators.

If the RandUtils notes that the current thread stated we are in test mode
before asking for a random number generator then it can return a random
generator with the test seed.  Otherwise, it can return a more robustly
seeded generator.  The generators in separate test threads are independent
objects with independent state.

> We were pursuing means to execute subsets of the tests in parallel in
> different JVMs, which can work and does work. We haven't yet found a way
to
> do it in Maven.

But this isn't necessary.  We can just fix RandUtils and be on our way.

Reply via email to