[TESTS] Fix test bugs for parent/child queries.

If you got a bad seed and tests.nightly=true, these tests would either call
Random#nextInt on `0` or trigger infinite loops.