Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ruanhaishen
hiredis
Commits
a68cb968
Commit
a68cb968
authored
Oct 18, 2010
by
Pieter Noordhuis
Browse files
Tests for context callbacks in non-blocking mode
parent
634314f3
Changes
1
Hide whitespace changes
Inline
Side-by-side
test.c
View file @
a68cb968
...
@@ -193,9 +193,46 @@ static void cleanup() {
...
@@ -193,9 +193,46 @@ static void cleanup() {
redisFree
(
c
);
redisFree
(
c
);
}
}
static
long
__test_callback_flags
=
0
;
static
void
__test_callback
(
redisContext
*
c
,
const
void
*
privdata
)
{
((
void
)
c
);
/* Shift to detect execution order */
__test_callback_flags
<<=
8
;
__test_callback_flags
|=
(
long
)
privdata
;
}
static
void
test_nonblocking_connection
()
{
redisContext
*
c
;
__test_callback_flags
=
0
;
test
(
"Calls command callback when command is issued: "
);
c
=
redisConnectNonBlock
(
"127.0.0.1"
,
6379
,
NULL
);
redisSetCommandCallback
(
c
,
__test_callback
,(
const
void
*
)
1
);
redisCommand
(
c
,
"PING"
);
test_cond
(
__test_callback_flags
==
1
);
redisFree
(
c
);
__test_callback_flags
=
0
;
test
(
"Calls disconnect callback on redisDisconnect: "
);
c
=
redisConnectNonBlock
(
"127.0.0.1"
,
6379
,
NULL
);
redisSetDisconnectCallback
(
c
,
__test_callback
,(
const
void
*
)
2
);
redisDisconnect
(
c
);
test_cond
(
__test_callback_flags
==
2
);
redisFree
(
c
);
__test_callback_flags
=
0
;
test
(
"Calls disconnect callback and free callback on redisFree: "
);
c
=
redisConnectNonBlock
(
"127.0.0.1"
,
6379
,
NULL
);
redisSetDisconnectCallback
(
c
,
__test_callback
,(
const
void
*
)
2
);
redisSetFreeCallback
(
c
,
__test_callback
,(
const
void
*
)
4
);
redisFree
(
c
);
test_cond
(
__test_callback_flags
==
((
2
<<
8
)
|
4
));
}
int
main
(
void
)
{
int
main
(
void
)
{
test_blocking_connection
();
test_blocking_connection
();
test_reply_reader
();
test_reply_reader
();
test_nonblocking_connection
();
test_throughput
();
test_throughput
();
cleanup
();
cleanup
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment