random-data-generator
random-data-generator copied to clipboard
Consecutive calls of `random` returns the same instance
Consecutive calls of random returns the same instance. Providing an integer to get multiple random elements will however generate different instances. How to overcome this?
(I'm not familiar with Shapless, just want to have simple instances fast.)
Hi @zzvara, this is actually not a Shapeless problem, but it is enforced by design of the library.
See https://github.com/DanielaSfregola/random-data-generator/pull/37#issuecomment-293801647 for an explanation of this issue.
Happy to discuss possible solutions or suggestions on how to improve this, if you have any.
I see, thanks for clarifying. I'll modify my test design according to this.
My idea would be to specify an another seed, a "transition seed", in which consecutive "picks" from the random[T] function with the same type would generate a new T as follows. Combine the (RANDOM_DATA_GENERATOR_SEED: Seed, NTH_CALL_FOR_T: Int, TRANSITION_SEED: Seed) to derive a new RANDOM_DATA_GENERATOR_SEED for that random generation. Still, "most" of the tests could be replicated.
On 2017-06-26 19:08:11, Daniela Sfregola [email protected] wrote: Hi @zzvara [https://github.com/zzvara], this is actually not a Shapeless problem, but it is enforced by design of the library. See #37 (comment) [https://github.com/DanielaSfregola/random-data-generator/pull/37#issuecomment-293801647] for an explanation of this issue. Happy to discuss possible solutions or suggestions on how to improve this, if you have any. — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub [https://github.com/DanielaSfregola/random-data-generator/issues/44#issuecomment-311121631], or mute the thread [https://github.com/notifications/unsubscribe-auth/AH--TVk-THCy0oLnR4ndPiiIitDL-nynks5sH-V4gaJpZM4OEUSf].
How would you handle that tests can run in parallel? i.e.: the order in which random is called is not guaranteed...
Encapsulate random into an Iterator, and each thread should acquire the iterator instead of accessing random directly. Iterator only needs to store NTH_CALL_FOR_T.
On 2017-06-26 20:07:19, Daniela Sfregola [email protected] wrote: How would you handle that tests can run in parallel? i.e.: the order in which random is called is not guaranteed... — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub [https://github.com/DanielaSfregola/random-data-generator/issues/44#issuecomment-311137009], or mute the thread [https://github.com/notifications/unsubscribe-auth/AH--TcNjvCEffZ1S5xapvP6TWPppIjPlks5sH_NWgaJpZM4OEUSf].
Give it a try @zzvara! Please, if it works I'd love to see a PR on this.
Cheers, D.
Hi @zzvara and @DanielaSfregola Why can't we go for "call by name" which makes the body of the method to execute, every time when this method is called? This makes every, consecutive call to random an actual invocation and will always return a new instance (instead of cached results). I am pretty sure that, I am missing some context. If so, please correct me. Thank you.
Hi @krishna-meduri, using simply random values will not work: we want the ability to reproduce a "randomly generated session", so that people can debug and fix their tests when a problematic session is found.
In the current implementation, requesting a random value of the same type will provide always the same value because we fix the seed.
I am pretty sure there must be a solution - such as having the idea of the global seed and a local seed that we can combine to obtain different values of the same type.
We "just" need to find a solution that guarantees that a session can be reproduced by fixing the seed independently from the execution order of a test.
@DanielaSfregola Got it. Thank you. Will try to see if I could come up with a solution and will update you.
I just use these 2 directly without random-data-generator:
import org.scalacheck.Arbitrary
import org.scalacheck.Gen
https://booksites.artima.com/scalacheck/examples/html/ch06.html