Hi, so I have a property test where I am using a custom generator to generate nested Json objects. When my second test runs for larger objects, it takes quite some time or it’s inconsistent. Sometimes takes 10 seconds and sometimes takes 100 seconds +. Is there anyway to make this code more efficient? I am currently resizing them to test for smaller and larger Json objects, would using the function sized be more efficient. Thank you in advance, here is the code.
@tag timeout: :infinity
property "when a & b are arbitrary large json objects; patch(a, diff(a,b)) == b" do
primitive = one_of([string(:printable), integer()])
json_fragment_gen =
tree(primitive, fn child_gen ->
StreamData.one_of([
# A JSON array
list_of(child_gen),
# A JSON object. Only supports string keys.
map_of(string(:printable), child_gen)
])
end)
# Only valid top-level JSON are objects and arrays
json_gen = json_fragment_gen |> filter(fn val -> is_map(val) end, 100)
check all(
map_a <- resize(json_gen, 900),
map_b <- resize(json_gen, 900),
map_a != map_b,
max_runs: 10
) do
IO.inspect(map_a)
assert map_b == js_patch(map_a, JsonDiffEx.diff(map_a, map_b))
on_exit(fn ->
:os.cmd('rm tmp/*.msgpack')