Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
Actor Framework
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cpp-libs
Actor Framework
Commits
8ae9b465
Commit
8ae9b465
authored
Jul 26, 2018
by
Joseph Noir
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix timeout test with actorized newb
parent
ae7a2709
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
19 deletions
+42
-19
libcaf_io/test/protocol_policy.cpp
libcaf_io/test/protocol_policy.cpp
+42
-19
No files found.
libcaf_io/test/protocol_policy.cpp
View file @
8ae9b465
...
...
@@ -178,6 +178,7 @@ struct accept_policy_impl : accept_policy {
}
void
init
(
newb_base
&
)
override
{
// TODO: there was something we wanted to do here ...
// nop
}
};
...
...
@@ -407,7 +408,7 @@ struct newb : public extend<scheduled_actor, newb<Message>>::template
// Probably required for reliability.
// void direct_enqueue(char* bytes, size_t count);
void
handle
(
Message
&
msg
)
{
v
irtual
v
oid
handle
(
Message
&
msg
)
{
using
tmp_t
=
mailbox_element_vals
<
Message
>
;
tmp_t
tmp
{
strong_actor_ptr
{},
make_message_id
(),
mailbox_element
::
forwarding_stack
{},
...
...
@@ -481,7 +482,9 @@ struct newb_acceptor : public network::event_handler {
native_socket
sock
;
transport_policy_ptr
transport
;
std
::
tie
(
sock
,
transport
)
=
acceptor
->
accept
();;
return
create_newb
(
sock
,
std
::
move
(
transport
));
auto
n
=
create_newb
(
sock
,
std
::
move
(
transport
));
acceptor
->
init
(
n
);
return
n
;
}
virtual
error
create_newb
(
native_socket
sock
,
transport_policy_ptr
pol
)
=
0
;
...
...
@@ -527,6 +530,10 @@ struct basp_policy {
}
error
read
(
char
*
bytes
,
size_t
count
)
{
if
(
count
<
header_size
)
{
CAF_MESSAGE
(
"data left in packet to small to contain the basp header"
);
return
sec
::
unexpected_message
;
}
new_basp_message
msg
;
binary_deserializer
bd
(
&
parent
->
backend
(),
bytes
,
count
);
bd
(
msg
.
header
);
...
...
@@ -656,6 +663,21 @@ struct dummy_basp_newb : newb<new_basp_message> {
// nop
}
void
handle
(
new_basp_message
&
msg
)
override
{
CAF_MESSAGE
(
"handling new basp message = "
<<
to_string
(
msg
));
CAF_ASSERT
(
!
expected
.
empty
());
auto
&
e
=
expected
.
front
();
CAF_CHECK_EQUAL
(
msg
.
header
.
from
,
get
<
1
>
(
e
).
from
);
CAF_CHECK_EQUAL
(
msg
.
header
.
to
,
get
<
1
>
(
e
).
to
);
int
pl
;
binary_deserializer
bd
(
&
backend_
,
msg
.
payload
,
msg
.
payload_size
);
bd
(
pl
);
CAF_CHECK_EQUAL
(
pl
,
get
<
2
>
(
e
));
std
::
vector
<
char
>
payload
{
msg
.
payload
,
msg
.
payload
+
msg
.
payload_size
};
messages
.
emplace_back
(
msg
,
payload
);
messages
.
back
().
first
.
payload
=
messages
.
back
().
second
.
data
();
}
behavior
make_behavior
()
override
{
set_default_handler
(
print_and_drop
);
return
{
...
...
@@ -668,6 +690,7 @@ struct dummy_basp_newb : newb<new_basp_message> {
},
// Append message to a buffer for checking the contents.
[
=
](
new_basp_message
&
msg
)
{
CAF_MESSAGE
(
"new basp message received = "
<<
to_string
(
msg
));
CAF_ASSERT
(
!
expected
.
empty
());
auto
&
e
=
expected
.
front
();
CAF_CHECK_EQUAL
(
msg
.
header
.
from
,
get
<
1
>
(
e
).
from
);
...
...
@@ -1016,6 +1039,7 @@ CAF_TEST(ordering and basp read event) {
auto
err
=
dummy
.
read_event
();
CAF_REQUIRE
(
!
err
);
CAF_MESSAGE
(
"check the basp header and payload"
);
CAF_REQUIRE
(
!
dummy
.
messages
.
empty
());
auto
&
msg
=
dummy
.
messages
.
front
().
first
;
CAF_CHECK_EQUAL
(
msg
.
header
.
from
,
bhdr
.
from
);
CAF_CHECK_EQUAL
(
msg
.
header
.
to
,
bhdr
.
to
);
...
...
@@ -1060,23 +1084,22 @@ CAF_TEST(ordering and basp read event with timeout) {
auto
err
=
dummy
.
read_event
();
CAF_REQUIRE
(
!
err
);
CAF_MESSAGE
(
"trigger waiting timeouts"
);
sched
.
run_dispatch_loop
();
auto
cnt
=
sched
.
clock
().
dispatch
();
CAF_REQUIRE
(
cnt
>
0
);
CAF_MESSAGE
(
"triggered "
<<
cnt
<<
" timeouts"
);
CAF_MESSAGE
(
"check if we have a pending timeout now"
);
CAF_REQUIRE
(
!
dummy
.
timeout_messages
.
empty
());
auto
&
timeout_pair
=
dummy
.
timeout_messages
.
back
();
CAF_CHECK_EQUAL
(
timeout_pair
.
first
,
ordering_atom
::
value
);
CAF_CHECK_EQUAL
(
timeout_pair
.
second
,
ohdr
.
seq_nr
);
CAF_REQUIRE
(
!
dummy
.
messages
.
empty
());
CAF_MESSAGE
(
"check delivered message"
);
auto
&
msg
=
dummy
.
messages
.
front
().
first
;
CAF_CHECK_EQUAL
(
msg
.
header
.
from
,
bhdr
.
from
);
CAF_CHECK_EQUAL
(
msg
.
header
.
to
,
bhdr
.
to
);
int
return_payload
=
0
;
memcpy
(
&
return_payload
,
msg
.
payload
,
msg
.
payload_size
);
CAF_CHECK_EQUAL
(
return_payload
,
payload
);
// Trigger timeout.
sched
.
dispatch
();
// Handle received message.
exec_all
();
//CAF_MESSAGE("check if we have a pending timeout now");
//CAF_REQUIRE(!dummy.timeout_messages.empty());
//auto& timeout_pair = dummy.timeout_messages.back();
//CAF_CHECK_EQUAL(timeout_pair.first, ordering_atom::value);
//CAF_CHECK_EQUAL(timeout_pair.second, ohdr.seq_nr);
//CAF_REQUIRE(!dummy.messages.empty());
//CAF_MESSAGE("check delivered message");
//auto& msg = dummy.messages.front().first;
//CAF_CHECK_EQUAL(msg.header.from, bhdr.from);
//CAF_CHECK_EQUAL(msg.header.to, bhdr.to);
//int return_payload = 0;
//CAF_CHECK_EQUAL(return_payload, payload);
}
...
...
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