From 028edae82e6c94cd4dce1d699c4e41d758ef9427 Mon Sep 17 00:00:00 2001 From: Joshua Colp Date: Tue, 2 Jun 2015 12:20:00 -0300 Subject: test_sorcery_memory_cache_thrash: Add unit tests for thrashing the memory cache. This change adds a CLI command which can perform memory cache thrashing as well as unit tests which perform thrashing under the following configurations: 1. Low number of unique objects that go stale after 1 second 2. Low number of unique objects that expire after 1 second 3. Low number of unique objects which are constantly updated 4. Large number of unique objects which exceed a defined cache size 5. Large number of unique objects which exceed a defined cache size that also expire and go stale rapidly 6. Large number of unique objects which expire and go stale rapidly 7. Large number of unique objects For all of the above there are a large number of threads constantly attempting to retrieve random objects and each test runs for a few seconds. ASTERISK-25067 Reported by: Matt Jordan Change-Id: I8c8ceff977332c80ed4a31f10d694d48552b2f78 --- res/res_sorcery_memory_cache.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'res/res_sorcery_memory_cache.c') diff --git a/res/res_sorcery_memory_cache.c b/res/res_sorcery_memory_cache.c index 57feb8f4f..451d2307a 100644 --- a/res/res_sorcery_memory_cache.c +++ b/res/res_sorcery_memory_cache.c @@ -418,6 +418,9 @@ static int remove_from_cache(struct sorcery_memory_cache *cache, const char *id, if (!hash_object) { return -1; } + + ast_assert(!strcmp(ast_sorcery_object_get_id(hash_object->object), id)); + oldest_object = ast_heap_peek(cache->object_heap, 1); heap_object = ast_heap_remove(cache->object_heap, hash_object); @@ -537,6 +540,8 @@ static int mark_object_as_stale_in_cache(struct sorcery_memory_cache *cache, con return -1; } + ast_assert(!strcmp(ast_sorcery_object_get_id(cached->object), id)); + object_stale_callback(cached, cache, 0); ao2_ref(cached, -1); @@ -718,6 +723,7 @@ static int sorcery_memory_cache_create(const struct ast_sorcery *sorcery, void * ao2_unlock(cache->objects); return -1; } + ast_assert(ao2_container_count(cache->objects) != cache->maximum_objects); } if (add_to_cache(cache, cached)) { ast_log(LOG_ERROR, "Unable to add object '%s' to the cache\n", @@ -826,6 +832,8 @@ static void *sorcery_memory_cache_retrieve_id(const struct ast_sorcery *sorcery, return NULL; } + ast_assert(!strcmp(ast_sorcery_object_get_id(cached->object), id)); + if (cache->object_lifetime_stale) { struct timeval elapsed; -- cgit v1.2.3