Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
L
libzmq
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
libzmq
Commits
f0168229
Commit
f0168229
authored
Aug 23, 2018
by
Simon Giesecke
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Problem: test_stream_disconnect not yet using unity
Solution: migrate to unity
parent
309fe2e6
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
111 additions
and
140 deletions
+111
-140
Makefile.am
Makefile.am
+2
-1
test_stream_disconnect.cpp
tests/test_stream_disconnect.cpp
+109
-139
No files found.
Makefile.am
View file @
f0168229
...
...
@@ -556,7 +556,8 @@ tests_test_stream_timeout_SOURCES = tests/test_stream_timeout.cpp
tests_test_stream_timeout_LDADD
=
src/libzmq.la
tests_test_stream_disconnect_SOURCES
=
tests/test_stream_disconnect.cpp
tests_test_stream_disconnect_LDADD
=
src/libzmq.la
tests_test_stream_disconnect_LDADD
=
src/libzmq.la
${
UNITY_LIBS
}
tests_test_stream_empty_CPPFLAGS
=
${
UNITY_CPPFLAGS
}
tests_test_disconnect_inproc_SOURCES
=
tests/test_disconnect_inproc.cpp
tests_test_disconnect_inproc_LDADD
=
src/libzmq.la
...
...
tests/test_stream_disconnect.cpp
View file @
f0168229
...
...
@@ -28,6 +28,17 @@
*/
#include "testutil.hpp"
#include "testutil_unity.hpp"
void
setUp
()
{
setup_test_context
();
}
void
tearDown
()
{
teardown_test_context
();
}
static
const
int
SERVER
=
0
;
static
const
int
CLIENT
=
1
;
...
...
@@ -56,33 +67,20 @@ bool has_more (void *socket_)
return
more
!=
0
;
}
bool
get_routing_id
(
void
*
socket_
,
char
*
data_
,
size_t
*
size_
)
{
int
rc
=
zmq_getsockopt
(
socket_
,
ZMQ_ROUTING_ID
,
data_
,
size_
);
return
rc
==
0
;
}
int
main
(
int
,
char
**
)
void
test_stream_disconnect
()
{
setup_test_environment
();
size_t
len
=
MAX_SOCKET_STRING
;
char
bind_endpoint
[
MAX_SOCKET_STRING
];
char
connect_endpoint
[
MAX_SOCKET_STRING
];
void
*
context
=
zmq_ctx_new
();
void
*
sockets
[
2
];
int
rc
=
0
;
sockets
[
SERVER
]
=
zmq_socket
(
context
,
ZMQ_STREAM
);
sockets
[
SERVER
]
=
test_context_socket
(
ZMQ_STREAM
);
int
enabled
=
1
;
rc
=
zmq_setsockopt
(
sockets
[
SERVER
],
ZMQ_STREAM_NOTIFY
,
&
enabled
,
sizeof
(
enabled
));
assert
(
rc
==
0
);
rc
=
zmq_bind
(
sockets
[
SERVER
],
"tcp://0.0.0.0:*"
);
assert
(
rc
==
0
);
rc
=
zmq_getsockopt
(
sockets
[
SERVER
],
ZMQ_LAST_ENDPOINT
,
bind_endpoint
,
&
len
);
assert
(
rc
==
0
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_setsockopt
(
sockets
[
SERVER
],
ZMQ_STREAM_NOTIFY
,
&
enabled
,
sizeof
(
enabled
)));
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_bind
(
sockets
[
SERVER
],
"tcp://0.0.0.0:*"
));
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_getsockopt
(
sockets
[
SERVER
],
ZMQ_LAST_ENDPOINT
,
bind_endpoint
,
&
len
));
// Apparently Windows can't connect to 0.0.0.0. A better fix would be welcome.
#ifdef ZMQ_HAVE_WINDOWS
...
...
@@ -92,76 +90,58 @@ int main (int, char **)
strcpy
(
connect_endpoint
,
bind_endpoint
);
#endif
sockets
[
CLIENT
]
=
zmq_socket
(
context
,
ZMQ_STREAM
);
rc
=
zmq_setsockopt
(
sockets
[
CLIENT
],
ZMQ_STREAM_NOTIFY
,
&
enabled
,
sizeof
(
enabled
));
assert
(
rc
==
0
);
rc
=
zmq_connect
(
sockets
[
CLIENT
],
connect_endpoint
);
assert
(
rc
==
0
);
sockets
[
CLIENT
]
=
test_context_socket
(
ZMQ_STREAM
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_setsockopt
(
sockets
[
CLIENT
],
ZMQ_STREAM_NOTIFY
,
&
enabled
,
sizeof
(
enabled
)));
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_connect
(
sockets
[
CLIENT
],
connect_endpoint
));
// wait for connect notification
// Server: Grab the 1st frame (peer routing id).
zmq_msg_t
peer_frame
;
rc
=
zmq_msg_init
(
&
peer_frame
);
assert
(
rc
==
0
);
rc
=
zmq_msg_recv
(
&
peer_frame
,
sockets
[
SERVER
],
0
);
assert
(
rc
!=
-
1
);
assert
(
zmq_msg_size
(
&
peer_frame
)
>
0
);
assert
(
has_more
(
sockets
[
SERVER
]));
rc
=
zmq_msg_close
(
&
peer_frame
);
assert
(
rc
==
0
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_msg_init
(
&
peer_frame
));
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_msg_recv
(
&
peer_frame
,
sockets
[
SERVER
],
0
));
TEST_ASSERT_GREATER_THAN_INT
(
0
,
zmq_msg_size
(
&
peer_frame
));
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_msg_close
(
&
peer_frame
));
TEST_ASSERT_TRUE
(
has_more
(
sockets
[
SERVER
]));
// Server: Grab the 2nd frame (actual payload).
zmq_msg_t
data_frame
;
rc
=
zmq_msg_init
(
&
data_frame
);
assert
(
rc
==
0
);
rc
=
zmq_msg_recv
(
&
data_frame
,
sockets
[
SERVER
],
0
);
assert
(
rc
!=
-
1
);
assert
(
zmq_msg_size
(
&
data_frame
)
==
0
);
rc
=
zmq_msg_close
(
&
data_frame
);
assert
(
rc
==
0
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_msg_init
(
&
data_frame
));
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_msg_recv
(
&
data_frame
,
sockets
[
SERVER
],
0
));
TEST_ASSERT_EQUAL_INT
(
0
,
zmq_msg_size
(
&
data_frame
));
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_msg_close
(
&
data_frame
));
// Client: Grab the 1st frame (peer routing id).
rc
=
zmq_msg_init
(
&
peer_frame
);
assert
(
rc
==
0
);
rc
=
zmq_msg_recv
(
&
peer_frame
,
sockets
[
CLIENT
],
0
);
assert
(
rc
!=
-
1
);
assert
(
zmq_msg_size
(
&
peer_frame
)
>
0
);
assert
(
has_more
(
sockets
[
CLIENT
]));
rc
=
zmq_msg_close
(
&
peer_frame
);
assert
(
rc
==
0
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_msg_init
(
&
peer_frame
));
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_msg_recv
(
&
peer_frame
,
sockets
[
CLIENT
],
0
));
TEST_ASSERT_GREATER_THAN_INT
(
0
,
zmq_msg_size
(
&
peer_frame
));
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_msg_close
(
&
peer_frame
));
TEST_ASSERT_TRUE
(
has_more
(
sockets
[
CLIENT
]));
// Client: Grab the 2nd frame (actual payload).
rc
=
zmq_msg_init
(
&
data_frame
);
assert
(
rc
==
0
);
rc
=
zmq_msg_recv
(
&
data_frame
,
sockets
[
CLIENT
],
0
);
assert
(
rc
!=
-
1
);
assert
(
zmq_msg_size
(
&
data_frame
)
==
0
);
rc
=
zmq_msg_close
(
&
data_frame
);
assert
(
rc
==
0
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_msg_init
(
&
data_frame
));
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_msg_recv
(
&
data_frame
,
sockets
[
CLIENT
],
0
));
TEST_ASSERT_EQUAL_INT
(
0
,
zmq_msg_size
(
&
data_frame
));
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_msg_close
(
&
data_frame
));
// Send initial message.
char
blob_data
[
256
];
size_t
blob_size
=
sizeof
(
blob_data
);
rc
=
zmq_getsockopt
(
sockets
[
CLIENT
],
ZMQ_ROUTING_ID
,
blob_data
,
&
blob_size
);
assert
(
rc
!=
-
1
);
assert
(
blob_size
>
0
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_getsockopt
(
sockets
[
CLIENT
],
ZMQ_ROUTING_ID
,
blob_data
,
&
blob_size
));
TEST_ASSERT_GREATER_THAN
(
0
,
blob_size
);
zmq_msg_t
msg
;
rc
=
zmq_msg_init_size
(
&
msg
,
blob_size
);
assert
(
rc
==
0
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_msg_init_size
(
&
msg
,
blob_size
));
memcpy
(
zmq_msg_data
(
&
msg
),
blob_data
,
blob_size
);
rc
=
zmq_msg_send
(
&
msg
,
sockets
[
dialog
[
0
].
turn
],
ZMQ_SNDMORE
);
assert
(
rc
!=
-
1
);
rc
=
zmq_msg_close
(
&
msg
);
assert
(
rc
==
0
);
rc
=
zmq_msg_init_size
(
&
msg
,
strlen
(
dialog
[
0
].
text
));
assert
(
rc
==
0
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_msg_send
(
&
msg
,
sockets
[
dialog
[
0
].
turn
],
ZMQ_SNDMORE
));
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_msg_close
(
&
msg
));
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_msg_init_size
(
&
msg
,
strlen
(
dialog
[
0
].
text
)));
memcpy
(
zmq_msg_data
(
&
msg
),
dialog
[
0
].
text
,
strlen
(
dialog
[
0
].
text
));
rc
=
zmq_msg_send
(
&
msg
,
sockets
[
dialog
[
0
].
turn
],
ZMQ_SNDMORE
);
assert
(
rc
!=
-
1
);
rc
=
zmq_msg_close
(
&
msg
);
assert
(
rc
==
0
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_msg_send
(
&
msg
,
sockets
[
dialog
[
0
].
turn
],
ZMQ_SNDMORE
));
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_msg_close
(
&
msg
));
// TODO: make sure this loop doesn't loop forever if something is wrong
// with the test (or the implementation).
...
...
@@ -173,28 +153,25 @@ int main (int, char **)
{
sockets
[
SERVER
],
0
,
ZMQ_POLLIN
,
0
},
{
sockets
[
CLIENT
],
0
,
ZMQ_POLLIN
,
0
},
};
int
rc
=
zmq_poll
(
items
,
2
,
100
);
assert
(
rc
>=
0
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_poll
(
items
,
2
,
100
));
// Check for data received by the server.
if
(
items
[
SERVER
].
revents
&
ZMQ_POLLIN
)
{
assert
(
dialog
[
step
].
turn
==
CLIENT
);
TEST_ASSERT_EQUAL_INT
(
CLIENT
,
dialog
[
step
].
turn
);
// Grab the 1st frame (peer routing id).
zmq_msg_t
peer_frame
;
rc
=
zmq_msg_init
(
&
peer_frame
);
assert
(
rc
==
0
);
rc
=
zmq_msg_recv
(
&
peer_frame
,
sockets
[
SERVER
],
0
);
assert
(
rc
!=
-
1
);
assert
(
zmq_msg_size
(
&
peer_frame
)
>
0
);
assert
(
has_more
(
sockets
[
SERVER
]));
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_msg_init
(
&
peer_frame
));
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_msg_recv
(
&
peer_frame
,
sockets
[
SERVER
],
0
));
TEST_ASSERT_GREATER_THAN_INT
(
0
,
zmq_msg_size
(
&
peer_frame
));
TEST_ASSERT_TRUE
(
has_more
(
sockets
[
SERVER
]));
// Grab the 2nd frame (actual payload).
zmq_msg_t
data_frame
;
rc
=
zmq_msg_init
(
&
data_frame
);
assert
(
rc
==
0
);
rc
=
zmq_msg_recv
(
&
data_frame
,
sockets
[
SERVER
],
0
);
assert
(
rc
!=
-
1
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_msg_init
(
&
data_frame
));
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_msg_recv
(
&
data_frame
,
sockets
[
SERVER
],
0
));
// Make sure payload matches what we expect.
const
char
*
const
data
=
(
const
char
*
)
zmq_msg_data
(
&
data_frame
);
...
...
@@ -203,97 +180,90 @@ int main (int, char **)
// should receive it as the last step in the dialogue.
if
(
size
==
0
)
{
++
step
;
assert
(
step
==
steps
);
TEST_ASSERT_EQUAL_INT
(
steps
,
step
);
}
else
{
assert
(
size
==
strlen
(
dialog
[
step
].
text
));
int
cmp
=
memcmp
(
dialog
[
step
].
text
,
data
,
size
);
assert
(
cmp
==
0
);
TEST_ASSERT_EQUAL_INT
(
strlen
(
dialog
[
step
].
text
),
size
);
TEST_ASSERT_EQUAL_STRING_LEN
(
dialog
[
step
].
text
,
data
,
size
);
++
step
;
assert
(
step
<
steps
);
TEST_ASSERT_LESS_THAN_INT
(
steps
,
step
);
// Prepare the response.
rc
=
zmq_msg_close
(
&
data_frame
);
assert
(
rc
==
0
);
rc
=
zmq_msg_init_size
(
&
data_frame
,
strlen
(
dialog
[
step
].
text
));
assert
(
rc
==
0
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_msg_close
(
&
data_frame
));
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_msg_init_size
(
&
data_frame
,
strlen
(
dialog
[
step
].
text
)));
memcpy
(
zmq_msg_data
(
&
data_frame
),
dialog
[
step
].
text
,
zmq_msg_size
(
&
data_frame
));
// Send the response.
rc
=
zmq_msg_send
(
&
peer_frame
,
sockets
[
SERVER
],
ZMQ_SNDMORE
);
assert
(
rc
!=
-
1
);
rc
=
zmq_msg_send
(
&
data_frame
,
sockets
[
SERVER
],
ZMQ_SNDMORE
);
assert
(
rc
!=
-
1
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_msg_send
(
&
peer_frame
,
sockets
[
SERVER
],
ZMQ_SNDMORE
)
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_msg_send
(
&
data_frame
,
sockets
[
SERVER
],
ZMQ_SNDMORE
)
);
}
// Release resources.
rc
=
zmq_msg_close
(
&
peer_frame
);
assert
(
rc
==
0
);
rc
=
zmq_msg_close
(
&
data_frame
);
assert
(
rc
==
0
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_msg_close
(
&
peer_frame
));
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_msg_close
(
&
data_frame
));
}
// Check for data received by the client.
if
(
items
[
CLIENT
].
revents
&
ZMQ_POLLIN
)
{
assert
(
dialog
[
step
].
turn
==
SERVER
);
TEST_ASSERT_EQUAL_INT
(
SERVER
,
dialog
[
step
].
turn
);
// Grab the 1st frame (peer routing id).
zmq_msg_t
peer_frame
;
rc
=
zmq_msg_init
(
&
peer_frame
);
assert
(
rc
==
0
);
rc
=
zmq_msg_recv
(
&
peer_frame
,
sockets
[
CLIENT
],
0
);
assert
(
rc
!=
-
1
);
assert
(
zmq_msg_size
(
&
peer_frame
)
>
0
);
assert
(
has_more
(
sockets
[
CLIENT
]));
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_msg_init
(
&
peer_frame
));
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_msg_recv
(
&
peer_frame
,
sockets
[
CLIENT
],
0
));
TEST_ASSERT_GREATER_THAN_INT
(
0
,
zmq_msg_size
(
&
peer_frame
));
TEST_ASSERT_TRUE
(
has_more
(
sockets
[
CLIENT
]));
// Grab the 2nd frame (actual payload).
zmq_msg_t
data_frame
;
rc
=
zmq_msg_init
(
&
data_frame
);
assert
(
rc
==
0
);
rc
=
zmq_msg_recv
(
&
data_frame
,
sockets
[
CLIENT
],
0
);
assert
(
rc
!=
-
1
);
assert
(
zmq_msg_size
(
&
data_frame
)
>
0
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_msg_init
(
&
data_frame
));
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_msg_recv
(
&
data_frame
,
sockets
[
CLIENT
],
0
));
TEST_ASSERT_GREATER_THAN_INT
(
0
,
zmq_msg_size
(
&
data_frame
));
// Make sure payload matches what we expect.
const
char
*
const
data
=
(
const
char
*
)
zmq_msg_data
(
&
data_frame
);
const
size_t
size
=
zmq_msg_size
(
&
data_frame
);
assert
(
size
==
strlen
(
dialog
[
step
].
text
));
int
cmp
=
memcmp
(
dialog
[
step
].
text
,
data
,
size
);
assert
(
cmp
==
0
);
TEST_ASSERT_EQUAL_INT
(
strlen
(
dialog
[
step
].
text
),
size
);
TEST_ASSERT_EQUAL_STRING_LEN
(
dialog
[
step
].
text
,
data
,
size
);
++
step
;
// Prepare the response (next line in the dialog).
assert
(
step
<
steps
);
rc
=
zmq_msg_close
(
&
data_frame
);
assert
(
rc
==
0
);
rc
=
zmq_msg_init_size
(
&
data_frame
,
strlen
(
dialog
[
step
].
text
));
assert
(
rc
==
0
);
TEST_ASSERT_LESS_THAN_INT
(
steps
,
step
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_msg_close
(
&
data_frame
));
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_msg_init_size
(
&
data_frame
,
strlen
(
dialog
[
step
].
text
)));
memcpy
(
zmq_msg_data
(
&
data_frame
),
dialog
[
step
].
text
,
zmq_msg_size
(
&
data_frame
));
// Send the response.
rc
=
zmq_msg_send
(
&
peer_frame
,
sockets
[
CLIENT
],
ZMQ_SNDMORE
);
assert
(
rc
!=
-
1
);
rc
=
zmq_msg_send
(
&
data_frame
,
sockets
[
CLIENT
],
ZMQ_SNDMORE
);
assert
(
rc
!=
-
1
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_msg_send
(
&
peer_frame
,
sockets
[
CLIENT
],
ZMQ_SNDMORE
)
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_msg_send
(
&
data_frame
,
sockets
[
CLIENT
],
ZMQ_SNDMORE
)
);
// Release resources.
rc
=
zmq_msg_close
(
&
peer_frame
);
assert
(
rc
==
0
);
rc
=
zmq_msg_close
(
&
data_frame
);
assert
(
rc
==
0
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_msg_close
(
&
peer_frame
));
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_msg_close
(
&
data_frame
));
}
}
assert
(
step
==
steps
);
rc
=
zmq_close
(
sockets
[
CLIENT
]);
assert
(
rc
==
0
);
rc
=
zmq_close
(
sockets
[
SERVER
]);
assert
(
rc
==
0
);
rc
=
zmq_ctx_term
(
context
);
assert
(
rc
==
0
);
return
0
;
TEST_ASSERT_EQUAL_INT
(
steps
,
step
);
test_context_socket_close
(
sockets
[
CLIENT
]);
test_context_socket_close
(
sockets
[
SERVER
]);
}
int
main
(
int
,
char
**
)
{
setup_test_environment
();
UNITY_BEGIN
();
RUN_TEST
(
test_stream_disconnect
);
return
UNITY_END
();
}
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