|
|
Testing ADK Agent Session Services - In-Memory vs Database
Author: Venkata Sudhakar
ShopMax India runs ADK agents with in-memory session services during development and with a Firestore-backed session service in production. Testing both backends ensures that session state - customer context, conversation history, and cart contents - behaves identically regardless of which service is active, so swapping backends does not introduce regressions in agent behavior.
ADK session services implement a common interface: create, get, update, and delete session state by session ID. In tests, write the same test suite against both an in-memory implementation and a mock database implementation. Assert that state written in one call is visible in the next, that updating state merges correctly, and that deleting a session removes all its data. Use a shared test fixture parameterised over both backends to avoid duplicating assertions.
The example below defines both an in-memory and a mock database session service for ShopMax India, then runs the same three tests against both using pytest parametrize. Tests cover create, update, and delete operations.
It gives the following output,
...... (6 passed in 0.01s)
In production, ShopMax India should add a session TTL of 30 minutes so abandoned carts do not accumulate in Firestore indefinitely. Use optimistic locking when updating session state to prevent race conditions when the same customer sends two rapid requests. Test the TTL expiry path explicitly by creating a session, advancing a mock clock past the TTL, and asserting that get returns an empty state rather than stale data.
|
|