Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
hiredis
Commits
a5acb589
Commit
a5acb589
authored
Nov 15, 2010
by
Pieter Noordhuis
Browse files
Redis >=2.1 replies with OK on QUIT, so make the test conditional
parent
1c394834
Changes
1
Hide whitespace changes
Inline
Side-by-side
test.c
View file @
a5acb589
...
...
@@ -76,30 +76,9 @@ static void test_format_commands() {
static
void
test_blocking_connection
()
{
redisContext
*
c
;
redisReply
*
reply
;
int
major
,
minor
;
__connect
(
&
c
);
test
(
"Returns I/O error when the connection is lost: "
);
reply
=
redisCommand
(
c
,
"QUIT"
);
test_cond
(
strcasecmp
(
reply
->
str
,
"OK"
)
==
0
&&
redisCommand
(
c
,
"PING"
)
==
NULL
);
/* Two conditions may happen, depending on the type of connection.
* When connected via TCP, the socket will not yet be aware of the closed
* connection and the write(2) call will succeed, but the read(2) will
* result in an EOF. When connected via Unix sockets, the socket will be
* immediately aware that it was closed and fail on the write(2) call. */
if
(
use_unix
)
{
fprintf
(
stderr
,
"Error: %s
\n
"
,
c
->
errstr
);
assert
(
c
->
err
==
REDIS_ERR_IO
&&
strcmp
(
c
->
errstr
,
"Broken pipe"
)
==
0
);
}
else
{
fprintf
(
stderr
,
"Error: %s
\n
"
,
c
->
errstr
);
assert
(
c
->
err
==
REDIS_ERR_EOF
&&
strcmp
(
c
->
errstr
,
"Server closed the connection"
)
==
0
);
}
freeReplyObject
(
reply
);
redisFree
(
c
);
__connect
(
&
c
);
/* reconnect */
test
(
"Is able to deliver commands: "
);
reply
=
redisCommand
(
c
,
"PING"
);
test_cond
(
reply
->
type
==
REDIS_REPLY_STATUS
&&
...
...
@@ -183,6 +162,47 @@ static void test_blocking_connection() {
reply
->
element
[
1
]
->
type
==
REDIS_REPLY_STATUS
&&
strcasecmp
(
reply
->
element
[
1
]
->
str
,
"pong"
)
==
0
);
freeReplyObject
(
reply
);
{
/* Find out Redis version to determine the path for the next test */
const
char
*
field
=
"redis_version:"
;
char
*
p
,
*
eptr
;
reply
=
redisCommand
(
c
,
"INFO"
);
p
=
strstr
(
reply
->
str
,
field
);
major
=
strtol
(
p
+
strlen
(
field
),
&
eptr
,
10
);
p
=
eptr
+
1
;
/* char next to the first "." */
minor
=
strtol
(
p
,
&
eptr
,
10
);
freeReplyObject
(
reply
);
}
test
(
"Returns I/O error when the connection is lost: "
);
reply
=
redisCommand
(
c
,
"QUIT"
);
if
(
major
>=
2
&&
minor
>
0
)
{
/* > 2.0 returns OK on QUIT and read() should be issued once more
* to know the descriptor is at EOF. */
test_cond
(
strcasecmp
(
reply
->
str
,
"OK"
)
==
0
&&
redisCommand
(
c
,
"PING"
)
==
NULL
);
freeReplyObject
(
reply
);
}
else
{
test_cond
(
reply
==
NULL
);
}
/* Two conditions may happen, depending on the type of connection.
* When connected via TCP, the socket will not yet be aware of the closed
* connection and the write(2) call will succeed, but the read(2) will
* result in an EOF. When connected via Unix sockets, the socket will be
* immediately aware that it was closed and fail on the write(2) call. */
if
(
use_unix
)
{
assert
(
c
->
err
==
REDIS_ERR_IO
&&
strcmp
(
c
->
errstr
,
"Broken pipe"
)
==
0
);
}
else
{
assert
(
c
->
err
==
REDIS_ERR_EOF
&&
strcmp
(
c
->
errstr
,
"Server closed the connection"
)
==
0
);
}
/* Clean up context and reconnect again */
redisFree
(
c
);
__connect
(
&
c
);
}
static
void
test_reply_reader
()
{
...
...
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