Testing a Basic Concurrent Cache
To use stateful tests, we’ll first need a stateful system to validate. In this section, we’ll use a cache implemented as an OTP gen_server. A common optimization pattern in Erlang is to use an ETS table for reads, and to make the writes sequential through calls to the gen_server, which ensures they’re safe. This creates a bit of contention on the write operations, so instead, we’ll try to write a cache that only uses ETS for all operations, and the gen_server’s job is just to keep the ETS table alive. The simple conceptual model—a cache handling data like a key-value store—along with an implementation dangerously accessing ETS tables concurrently makes this is a great candidate to demonstrate stateful property ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access