Stream: helpdesk (published)

Topic: Reproducible UUIDs for tests


view this post on Zulip Sascha Mann (Nov 05 2022 at 10:02):

#35872 changed uuid4() to not use the global RNG anymore which means seed! will no longer affect it.

I have a function that generates a UUID and writes it to a file. The tests should check that the file contains that UUID, therefore it needs to be reproducible somehow. Real example: julia-actions/GitHubActions.jl#26

Is there a good way to accomplish this without creating a custom RNG in the library code that can then be seeded in the test code? The latter would work but it seems like a bad practice

view this post on Zulip Sukera (Nov 05 2022 at 10:06):

(deleted)

view this post on Zulip Sukera (Nov 05 2022 at 10:07):

well I should read PRs before commenting

view this post on Zulip Sukera (Nov 05 2022 at 10:07):

in any case, having a dedicated RNG for your usecase is perfectly fine

view this post on Zulip Sukera (Nov 05 2022 at 10:08):

another option would be to see if there's a need to check for the exact UUID at all, or if it's sufficient that _a_ UUID is there

view this post on Zulip Sascha Mann (Nov 05 2022 at 10:19):

Thanks, I'll use a dedicated RNG then

view this post on Zulip Sascha Mann (Nov 05 2022 at 10:20):

Checking if it contains some UUID in the right places would work for all but one edge case, otherwise I like that idea

view this post on Zulip Sascha Mann (Nov 05 2022 at 10:36):

I think I found an even better way in the upstream code that I'm reimplementing in Julia: Instead of seeding the RNG, mock uuid4() to return a specific UUID4. That addresses the edge case and doesn't require changes to the library code itself


Last updated: Dec 28 2024 at 04:38 UTC