The FreeRADIUS server $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Loading...
Searching...
No Matches
test.c
Go to the documentation of this file.
1/*
2 * cc -g3 -Wall -DHAVE_DLFCN_H -I../../../src -include freeradius-devel/build.h -L../../../build/lib/local/.libs -ltalloc -lhiredis -lfreeradius-unlang -lfreeradius-util -lfreeradius-server -o test_redis test.c redis.c io.c crc16.c
3 */
4#include <freeradius-devel/util/acutest.h>
5#include "base.h"
6#include "io.h"
7#include "pipeline.h"
8
9#define DEBUG_LVL_SET if (test_verbose_level_ >= 3) fr_debug_lvl = L_DBG_LVL_4 + 1
10
11
12typedef struct {
14 uint64_t enqueued;
16
17static void _command_complete(request_t *request, fr_dlist_head_t *completed, void *rctx)
18{
19 fr_time_t io_stop;
20 fr_time_delta_t io_time;
21 redis_pipeline_stats_t *stats = rctx;
22 fr_redis_command_t *cmd = talloc_get_type_abort(fr_dlist_head(completed), fr_redis_command_t);
23 redisReply *reply = fr_redis_command_get_result(cmd);
24 io_stop = fr_time();
25 io_time = io_stop - stats->start;
26
27 INFO("I/O time %pV (%u rps)",
28 fr_box_time_delta(io_time),
29 (uint32_t)(stats->enqueued / ((float)io_time / NSEC)));
30
31 fr_assert(fr_dlist_num_elements(completed) == stats->enqueued);
32}
33
34static void _command_failed(request_t *request, fr_dlist_head_t *completed, void *rctx)
35{
36 TEST_CHECK(0);
37}
38
39static void test_basic_connection(void)
40{
41 TALLOC_CTX *ctx;
43 int events;
45 fr_redis_cluster_thread_t *cluster_thread;
46 fr_redis_trunk_t *rtrunk;
47 connection_conf_t conn_conf;
48 trunk_conf_t trunk_conf;
49 size_t i;
51
53
54 memset(&conn_conf, 0, sizeof(conn_conf));
55 memset(&trunk_conf, 0, sizeof(trunk_conf));
56
57 trunk_conf.conn_conf = &conn_conf;
58
59 ctx = talloc_init("test_ctx");
60 el = fr_event_list_alloc(ctx, NULL, NULL);
61
63 /*
64 * Enqueue 10 set commands
65 */
66 for (i = 0; i < 1000000; i++) {
67 TEST_CHECK(fr_redis_command_preformatted_add(cmds, "PING", sizeof("PING") - 1) == FR_REDIS_PIPELINE_OK);
68 }
69
70 cluster_thread = fr_redis_cluster_thread_alloc(ctx, el, &trunk_conf);
71 rtrunk = fr_redis_trunk_alloc(cluster_thread, &(fr_redis_io_conf_t){ .hostname = "127.0.0.1", .port = 30001 });
72
73 stats.enqueued = 1000000;
74 stats.start = fr_time();
75
77
78 do {
79 events = fr_event_corral(el, fr_time(), true);
81 } while (events > 0);
82}
83
85 /*
86 * Basic tests
87 */
88 { "Basic - Connection", test_basic_connection},
89 { NULL }
90};
#define TEST_CHECK(cond)
Definition acutest.h:85
static void * fr_dlist_head(fr_dlist_head_t const *list_head)
Return the HEAD item of a list or NULL if the list is empty.
Definition dlist.h:486
static unsigned int fr_dlist_num_elements(fr_dlist_head_t const *head)
Return the number of elements in the dlist.
Definition dlist.h:939
Head of a doubly linked list.
Definition dlist.h:51
void fr_event_service(fr_event_list_t *el)
Service any outstanding timer or file descriptor events.
Definition event.c:2549
int fr_event_corral(fr_event_list_t *el, fr_time_t now, bool wait)
Gather outstanding timer and file descriptor events.
Definition event.c:2414
fr_event_list_t * fr_event_list_alloc(TALLOC_CTX *ctx, fr_event_status_cb_t status, void *status_uctx)
Initialise a new event list.
Definition event.c:2899
Stores all information relating to an event list.
Definition event.c:411
unsigned int uint32_t
Function prototypes and datatypes for the REST (HTTP) transport.
fr_redis_cluster_thread_t * fr_redis_cluster_thread_alloc(TALLOC_CTX *ctx, fr_event_list_t *el, trunk_conf_t const *tconf)
Allocate per-thread, per-cluster instance.
Definition pipeline.c:647
fr_redis_command_set_t * fr_redis_command_set_alloc(TALLOC_CTX *ctx, request_t *request, fr_redis_command_set_complete_t complete, fr_redis_command_set_fail_t fail, void *rctx)
Allocate a new command set.
Definition pipeline.c:206
fr_redis_pipeline_status_t redis_command_set_enqueue(fr_redis_trunk_t *rtrunk, fr_redis_command_set_t *cmds)
Enqueue a command set on a specific trunk.
Definition pipeline.c:392
fr_redis_pipeline_status_t fr_redis_command_preformatted_add(fr_redis_command_set_t *cmds, char const *cmd_str, size_t cmd_len)
Add a preformatted/expanded command to the command set.
Definition pipeline.c:292
fr_redis_trunk_t * fr_redis_trunk_alloc(fr_redis_cluster_thread_t *cluster_thread, fr_redis_io_conf_t const *io_conf)
Allocate a new trunk.
Definition pipeline.c:615
redisReply * fr_redis_command_get_result(fr_redis_command_t *cmd)
Definition pipeline.c:270
Thread local state for a cluster.
Definition pipeline.c:39
Represents a single command.
Definition pipeline.c:67
Represents a collection of pipelined commands.
Definition pipeline.c:87
Redis asynchronous command pipelining.
@ FR_REDIS_PIPELINE_OK
No failure.
Definition pipeline.h:42
#define fr_assert(_expr)
Definition rad_assert.h:38
#define INFO(fmt,...)
Definition radict.c:54
static fr_event_list_t * events
Definition radsniff.c:59
#define fr_time()
Allow us to arbitrarily manipulate time.
Definition state_test.c:8
#define DEBUG_LVL_SET
Definition test.c:9
TEST_LIST
Definition test.c:84
static void _command_failed(request_t *request, fr_dlist_head_t *completed, void *rctx)
Definition test.c:34
uint64_t enqueued
Definition test.c:14
fr_time_t start
Definition test.c:13
static void _command_complete(request_t *request, fr_dlist_head_t *completed, void *rctx)
Definition test.c:17
static void test_basic_connection(void)
Definition test.c:39
#define NSEC
Definition time.h:379
A time delta, a difference in time measured in nanoseconds.
Definition time.h:80
"server local" time.
Definition time.h:69
connection_conf_t const * conn_conf
Connection configuration.
Definition trunk.h:225
Common configuration parameters for a trunk.
Definition trunk.h:224
static fr_event_list_t * el
Master include file to access all functions and structures in the library.
#define fr_box_time_delta(_val)
Definition value.h:343