Fork me on GitHub
#clojure-spec
<
2019-01-07
>
urzds14:01:23

Are logs of this channel available somewhere?

kenny21:01:46

Is there a way to limit the size of the a map generated from (gen/generate (s/gen map?))?

taylor21:01:02

generate can take another argument size e.g. (gen/generate (s/gen map?) 10)

taylor21:01:43

I think the general range of sizes is 0-200 maybe?

taylor21:01:19

looks like it uses 30 by default

Alex Miller (Clojure team)21:01:50

no, but you can use something like (s/map-of any? any? :gen-max 5)

5
borkdude21:01:23

is there a better way of making a transducer spec than ifn?? e.g. this works, but it shouldn’t:

(s/conform (:ret (s/get-spec `map)) [1 2 3])
[:transducer [1 2 3]]

Alex Miller (Clojure team)21:01:35

I’ve looked at it, and generally I’d say no

Alex Miller (Clojure team)21:01:06

this is well outside the sweet spot for spec

kenny21:01:17

I'm seeing strange behavior when running clojure.spec.test.alpha/check on an fdef'ed function. I have a prn as the first line in my function that prints out the size of the args. When the generative tests first start running, I get print statements out rapidly. After running for a few seconds, the print statements slow down to once every second. After 10-20s more, they speed up again. This goes on for about 10 mins until check returns. At first I thought it was due to test.check generating large maps so I changed the :args in my fdef to use (s/map-of any? any? :gen-max 5). Then I thought it was a JVM memory issue but (.maxMemory (Runtime/getRuntime)) says the JVM has over 7gb available. I haven't seen this behavior with spec check before. Any ideas on what could cause this?

Alex Miller (Clojure team)21:01:55

sounds awfully like GC churn to me

Alex Miller (Clojure team)21:01:37

do you have an fspec anywhere?

kenny22:01:12

Not in this function.

Alex Miller (Clojure team)22:01:30

you can add -verbose:gc to watch the gc

Alex Miller (Clojure team)22:01:15

you could isolate just the gen on the args if you suspect that it’s it

Alex Miller (Clojure team)22:01:03

something like

(gen/sample (s/gen (:args (s/get-spec `foo))) 1000)

kenny22:01:57

Generating the args like you have there takes about 30s. I'll add the gc flag to see if it sheds any light.

kenny22:01:54

Added the gc flag. I get a message that looks like this [GC (Allocation Failure) 2477246K->1068161K(3133952K), 0.1575999 secs] printed out every second or so.

kenny23:01:08

This is what the output with the -verbose:gc flag looks like https://pastebin.com/raw/XCxMykgq. The numbers are the count on the two args this function takes.

kenny23:01:58

Updated to test.check 0.10.0-alpha3 and the problem goes away.

lilactown23:01:52

I have a map like:

{::kind :bool
 ::default true}
that, given a different ::kind, might need a different predicate for ::default. E.g.:
{::kind :string
 ::default "foo"}
What's the best way to model this in spec? I thought multi-specs would work, but I'm still struggling with the fact that the name of the spec I pass into s/keys needs to match the key, which makes overloading ::default difficult

mattly23:01:30

@lilactown I've done this with s/or specs

mattly23:01:37

I can give you an example in our work slack