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
bbe007a7
Commit
bbe007a7
authored
Oct 19, 2010
by
Pieter Noordhuis
Browse files
Test helper for creating a non-blocking connection
parent
e3067fe2
Changes
1
Hide whitespace changes
Inline
Side-by-side
test.c
View file @
bbe007a7
...
@@ -211,62 +211,65 @@ static void __test_reply_callback(redisContext *c, redisReply *reply, void *priv
...
@@ -211,62 +211,65 @@ static void __test_reply_callback(redisContext *c, redisReply *reply, void *priv
freeReplyObject
(
reply
);
freeReplyObject
(
reply
);
}
}
static
redisContext
*
__connect_nonblock
()
{
/* Reset callback flags */
__test_callback_flags
=
__test_reply_callback_flags
=
0
;
return
redisConnectNonBlock
(
"127.0.0.1"
,
6379
,
NULL
);
}
static
void
test_nonblocking_connection
()
{
static
void
test_nonblocking_connection
()
{
redisContext
*
c
;
redisContext
*
c
;
int
wdone
=
0
;
int
wdone
=
0
;
__test_callback_flags
=
0
;
test
(
"Calls command callback when command is issued: "
);
test
(
"Calls command callback when command is issued: "
);
c
=
redisC
onnect
N
on
B
lock
(
"127.0.0.1"
,
6379
,
NULL
);
c
=
__c
onnect
_n
on
b
lock
();
redisSetCommandCallback
(
c
,
__test_callback
,(
void
*
)
1
);
redisSetCommandCallback
(
c
,
__test_callback
,(
void
*
)
1
);
redisCommand
(
c
,
"PING"
);
redisCommand
(
c
,
"PING"
);
test_cond
(
__test_callback_flags
==
1
);
test_cond
(
__test_callback_flags
==
1
);
redisFree
(
c
);
redisFree
(
c
);
__test_callback_flags
=
0
;
test
(
"Calls disconnect callback on redisDisconnect: "
);
test
(
"Calls disconnect callback on redisDisconnect: "
);
c
=
redisC
onnect
N
on
B
lock
(
"127.0.0.1"
,
6379
,
NULL
);
c
=
__c
onnect
_n
on
b
lock
();
redisSetDisconnectCallback
(
c
,
__test_callback
,(
void
*
)
2
);
redisSetDisconnectCallback
(
c
,
__test_callback
,(
void
*
)
2
);
redisDisconnect
(
c
);
redisDisconnect
(
c
);
test_cond
(
__test_callback_flags
==
2
);
test_cond
(
__test_callback_flags
==
2
);
redisFree
(
c
);
redisFree
(
c
);
__test_callback_flags
=
0
;
test
(
"Calls disconnect callback and free callback on redisFree: "
);
test
(
"Calls disconnect callback and free callback on redisFree: "
);
c
=
redisC
onnect
N
on
B
lock
(
"127.0.0.1"
,
6379
,
NULL
);
c
=
__c
onnect
_n
on
b
lock
();
redisSetDisconnectCallback
(
c
,
__test_callback
,(
void
*
)
2
);
redisSetDisconnectCallback
(
c
,
__test_callback
,(
void
*
)
2
);
redisSetFreeCallback
(
c
,
__test_callback
,(
void
*
)
4
);
redisSetFreeCallback
(
c
,
__test_callback
,(
void
*
)
4
);
redisFree
(
c
);
redisFree
(
c
);
test_cond
(
__test_callback_flags
==
((
2
<<
8
)
|
4
));
test_cond
(
__test_callback_flags
==
((
2
<<
8
)
|
4
));
test
(
"redisBufferWrite against empty write buffer: "
);
test
(
"redisBufferWrite against empty write buffer: "
);
c
=
redisC
onnect
N
on
B
lock
(
"127.0.0.1"
,
6379
,
NULL
);
c
=
__c
onnect
_n
on
b
lock
();
test_cond
(
redisBufferWrite
(
c
,
&
wdone
)
==
REDIS_OK
&&
wdone
==
1
);
test_cond
(
redisBufferWrite
(
c
,
&
wdone
)
==
REDIS_OK
&&
wdone
==
1
);
redisFree
(
c
);
redisFree
(
c
);
test
(
"redisBufferWrite against not yet connected fd: "
);
test
(
"redisBufferWrite against not yet connected fd: "
);
c
=
redisC
onnect
N
on
B
lock
(
"127.0.0.1"
,
6379
,
NULL
);
c
=
__c
onnect
_n
on
b
lock
();
redisCommand
(
c
,
"PING"
);
redisCommand
(
c
,
"PING"
);
test_cond
(
redisBufferWrite
(
c
,
NULL
)
==
REDIS_ERR
&&
test_cond
(
redisBufferWrite
(
c
,
NULL
)
==
REDIS_ERR
&&
strncmp
(
c
->
error
,
"write:"
,
6
)
==
0
);
strncmp
(
c
->
error
,
"write:"
,
6
)
==
0
);
redisFree
(
c
);
redisFree
(
c
);
test
(
"redisBufferWrite against closed fd: "
);
test
(
"redisBufferWrite against closed fd: "
);
c
=
redisC
onnect
N
on
B
lock
(
"127.0.0.1"
,
6379
,
NULL
);
c
=
__c
onnect
_n
on
b
lock
();
redisCommand
(
c
,
"PING"
);
redisCommand
(
c
,
"PING"
);
redisDisconnect
(
c
);
redisDisconnect
(
c
);
test_cond
(
redisBufferWrite
(
c
,
NULL
)
==
REDIS_ERR
&&
test_cond
(
redisBufferWrite
(
c
,
NULL
)
==
REDIS_ERR
&&
strncmp
(
c
->
error
,
"write:"
,
6
)
==
0
);
strncmp
(
c
->
error
,
"write:"
,
6
)
==
0
);
redisFree
(
c
);
redisFree
(
c
);
wdone
=
__test_reply_callback_flags
=
0
;
test
(
"Process callbacks in the right sequence: "
);
test
(
"Process callbacks in the right sequence: "
);
c
=
redisC
onnect
N
on
B
lock
(
"127.0.0.1"
,
6379
,
NULL
);
c
=
__c
onnect
_n
on
b
lock
();
redisCommandWithCallback
(
c
,
__test_reply_callback
,(
void
*
)
1
,
"PING"
);
redisCommandWithCallback
(
c
,
__test_reply_callback
,(
void
*
)
1
,
"PING"
);
redisCommandWithCallback
(
c
,
__test_reply_callback
,(
void
*
)
2
,
"PING"
);
redisCommandWithCallback
(
c
,
__test_reply_callback
,(
void
*
)
2
,
"PING"
);
redisCommandWithCallback
(
c
,
__test_reply_callback
,(
void
*
)
3
,
"PING"
);
redisCommandWithCallback
(
c
,
__test_reply_callback
,(
void
*
)
3
,
"PING"
);
/* Write output buffer */
/* Write output buffer */
wdone
=
0
;
while
(
!
wdone
)
{
while
(
!
wdone
)
{
usleep
(
500
);
usleep
(
500
);
redisBufferWrite
(
c
,
&
wdone
);
redisBufferWrite
(
c
,
&
wdone
);
...
...
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