igalic
Hi folks,
I’m trying to transform our tests for AuthToken (a wrapper around JOSE) to ExUnitProperties. But I’m kinda failing at the most basic task of transforming a simple function into a generator. What I’ve done is this:
defp stream_authtoken_keys(_seed, _range) do
Stream.repeatedly(&AuthToken.generate_key/0)
end
defp gen_authtoken_key() do
%StreamData{generator: &stream_authtoken_keys/2}
end
However, when trying to use it…
describe "keys" do
property "generate_key/0 returns a valid AES128 key" do
check all authtoken_key <- gen_authtoken_key() do
{:ok, key} = authtoken_key
assert byte_size(key) == 16
end
end
end
I get the following error:
1) property keys generate_key/0 returns a valid AES128 key (AuthTokenTest)
test/authtoken_test.exs:23
** (MatchError) no match of right hand side value: #Function<51.91433161/2 in Stream.repeatedly/1>
code: check all authtoken_key <- gen_authtoken_key() do
stacktrace:
(stream_data) lib/stream_data.ex:203: StreamData.bind_filter/5
(stream_data) lib/stream_data.ex:346: anonymous fn/5 in StreamData.bind_filter/3
(stream_data) lib/stream_data.ex:203: StreamData.check_all/6
test/authtoken_test.exs:24: (test)
Trending in Questions
Hello everyone!
I am new to coding with Elixir/Erlang. And i am looking for some utilities for fuzzing testing like AFL++.
Does anyone ...
New
I’m very new to Elixir, so sorry if this is a silly question:
I am wondering what happens to the mailbox of a process when the machine i...
New
How do I tell Hologram not to escape HTML when substituting into templates?
{Textile.render(@product.long_description)}
escapes the HTM...
New
Background
When trying to execute mix release on a Windows 11 machine for a Phoenix project I get the following error:
* assembling mark...
New
I load tested a plain Phoenix chat app backed by Postgres with 100 million messages in it, everything on default settings, to see what br...
New
I’d like to create a file with 600 permissions (rw-------), but there’s a race condition if I create it and then change the permissions. ...
New
Is there a way to import record definitions in the iex shell for pretty printing (similar to the rr command in the erl shell)? This woul...
New
Other Trending Topics
Edit: 2026 May 15 - This post is archived.
Mob is alive!!
Main docs: mob v0.7.11 — Documentation
A bit of explanation for the slightly c...
New
Hey there,
I haven’t seen a list of useful Elixir specific skills for the popular AI tools yet so I’m starting one here with my first.
...
New
Hi everyone :waving_hand:
I wanted to share something I’ve been building — NowBlind, a random chat app designed to help people discover ...
New
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
(I just needed to vent somewhere and LinkedIn is full of hope, or hype, I’m not sure which exactly)
AI dream has many faces, but general...
New
Localize is the next generation localisation library for Elixir. Think of it as ex_cldr version 3.0. The first version will be released ...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #code-sync
- #discussion
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #ai
- #elixirconf-us
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #blog-post
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #security
- #elixirconf-eu
- #processes
- #api
- #forms
- #hex










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
DanCouper
Just as simple as
authtoken_keyrather thankey?igalic
After posting this in elixir (on irc & discord) I got a very decent reply that works out pretty fine, so I’m gonna close this topic for now with it!
First off, trying to generate
%StreamData{}myself, is kinda bad form, since it’s basically a private struct…We looked for alternatives, and found
StreamData.constant/0. However, on its own, it always generates the same value.Which makes a certain amount of sense when you think about how it’s called:
The clue came from @michalmuskala:
and the code we now have from @ericmj
what we’re doing here is using
StreamData.constant/1as a sort of clock generator, that drives the call ofAuthToken.generate_key/0… and it’s nice start, but we’re needlessly generating alist_ofwhich we thenmapSo let’s update this with all responses below!
This is much cleaner! Since we use
bind/2, which is essentially made for this… better see what’s going on, we can use pipes to extract the flow:We feed a stream of
:unusedintogen_tickerlambda, just so it will be constantly called. Since our call toAuthToken.generate_key/0is wrapped in said lambda, it will be executed on every call, rather than onge_ticker’s declaration. Finally, we pass the so generated%StreamData{}intounshrinkable/0(because it is) before returning it.igalic
i think that was just an awkward copy/paste error… and i should fix this in the original post
igalic
was missing in my paste (not the error causing code)
ericmj
I found a (maybe) cleaner way of doing it that doesn’t involve generating a list:
I haven’t tested this so I can’t verify that it works.
EDIT: @whatyouhide has a more concise solution below: How to create a custom StreamData Generator - #12 by whatyouhide
LostKobrakai
It might also be good to make the generator unshrinkable, because shrinking doesn’t seem to make sense in that context.
igalic
I really couldn’t figure this out from the documentation…
maybe we should add something to the docs that helps people figure out how to create custom generators
@michalmuskala suggested to have
StreamData.repeatedly/1. I was thinking maybe a better way would be to have a way of converting aStreamto aStreamData.LostKobrakai
I found it quite easy to build more complex generators out of the basic generators already in the streamdata module, but I’ve to say that your usecase really doesn’t seem very well supported by the current functions.
anthonator
@igalic’s approach only seems to work if you use the generator in a
check. If you try to use it in agenyou run into a the issue of the value being considered a constant so it’s the same on each run through. Any way around this?anthonator
I was able to get this working. Turned out
checkwas swallowing another error.