January 2019
Intermediate to advanced
376 pages
8h 49m
English
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 ...