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
de72dfdb
Commit
de72dfdb
authored
Jul 13, 2017
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make authentication test deterministic
parent
195eba3a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
71 additions
and
17 deletions
+71
-17
libcaf_openssl/test/authentication.cpp
libcaf_openssl/test/authentication.cpp
+71
-17
No files found.
libcaf_openssl/test/authentication.cpp
View file @
de72dfdb
...
...
@@ -48,9 +48,10 @@ public:
load
<
io
::
middleman
>
();
load
<
openssl
::
manager
>
();
add_message_type
<
std
::
vector
<
int
>>
(
"std::vector<int>"
);
actor_system_config
::
parse
(
test
::
engine
::
argc
(),
test
::
engine
::
argv
());
scheduler_max_threads
=
1
;
actor_system_config
::
parse
(
test
::
engine
::
argc
(),
test
::
engine
::
argv
());
middleman_detach_multiplexer
=
false
;
middleman_detach_utility_actors
=
false
;
scheduler_policy
=
atom
(
"testing"
);
}
static
std
::
string
data_dir
()
{
...
...
@@ -70,36 +71,38 @@ public:
behavior
make_pong_behavior
()
{
return
{
[](
int
val
)
->
int
{
CAF_MESSAGE
(
"pong with "
<<
++
val
);
++
val
;
CAF_MESSAGE
(
"pong "
<<
val
);
return
val
;
}
};
}
behavior
make_ping_behavior
(
event_based_actor
*
self
,
const
actor
&
pong
)
{
CAF_MESSAGE
(
"ping
with
"
<<
0
);
CAF_MESSAGE
(
"ping "
<<
0
);
self
->
send
(
pong
,
0
);
return
{
[
=
](
int
val
)
->
int
{
if
(
val
==
3
)
{
CAF_MESSAGE
(
"ping with exit"
);
self
->
send_exit
(
self
->
current_sender
(),
exit_reason
::
user_shutdown
);
CAF_MESSAGE
(
"ping quits"
);
CAF_MESSAGE
(
"ping "
<<
val
);
if
(
val
>=
3
)
{
CAF_MESSAGE
(
"terminate ping"
);
self
->
quit
();
}
CAF_MESSAGE
(
"ping with "
<<
val
);
return
val
;
}
};
}
struct
fixture
{
using
sched_t
=
scheduler
::
test_coordinator
;
config
server_side_config
;
config
client_side_config
;
bool
initialized
;
union
{
actor_system
server_side
;
};
union
{
actor_system
client_side
;
};
sched_t
*
ssched
;
sched_t
*
csched
;
fixture
()
:
initialized
(
false
)
{
// nop
...
...
@@ -136,11 +139,41 @@ struct fixture {
}
*
x
.
second
=
std
::
move
(
path
);
}
CAF_MESSAGE
(
"initialize server side"
);
new
(
&
server_side
)
actor_system
(
server_side_config
);
CAF_MESSAGE
(
"initialize client side"
);
new
(
&
client_side
)
actor_system
(
client_side_config
);
ssched
=
&
dynamic_cast
<
sched_t
&>
(
server_side
.
scheduler
());
csched
=
&
dynamic_cast
<
sched_t
&>
(
client_side
.
scheduler
());
initialized
=
true
;
return
true
;
}
sched_t
&
sched_by_sys
(
actor_system
&
sys
)
{
return
&
sys
==
&
server_side
?
*
ssched
:
*
csched
;
}
bool
exec_one
(
actor_system
&
sys
)
{
CAF_ASSERT
(
initialized
);
CAF_PUSH_AID
(
0
);
CAF_SET_LOGGER_SYS
(
&
sys
);
return
sched_by_sys
(
sys
).
try_run_once
()
||
sys
.
middleman
().
backend
().
try_run_once
();
}
void
exec_loop
(
actor_system
&
sys
)
{
while
(
exec_one
(
sys
))
;
// nop
}
void
exec_loop
()
{
while
(
exec_one
(
client_side
)
|
exec_one
(
server_side
))
;
// nop
}
void
loop_after_next_enqueue
(
actor_system
&
sys
)
{
auto
s
=
&
sys
==
&
server_side
?
ssched
:
csched
;
s
->
after_next_enqueue
([
=
]
{
exec_loop
();
});
}
};
}
// namespace <anonymous>
...
...
@@ -154,23 +187,44 @@ CAF_TEST(authentication_succes) {
if
(
!
init
(
false
))
return
;
// server side
CAF_EXP_THROW
(
port
,
publish
(
server_side
.
spawn
(
make_pong_behavior
),
0
,
local_host
));
CAF_MESSAGE
(
"spawn pong on server"
);
auto
spong
=
server_side
.
spawn
(
make_pong_behavior
);
exec_loop
();
loop_after_next_enqueue
(
server_side
);
CAF_MESSAGE
(
"publish pong"
);
CAF_EXP_THROW
(
port
,
publish
(
spong
,
0
,
local_host
));
exec_loop
();
// client side
CAF_MESSAGE
(
"connect to pong via port "
<<
port
);
loop_after_next_enqueue
(
client_side
);
CAF_EXP_THROW
(
pong
,
remote_actor
(
client_side
,
local_host
,
port
));
CAF_MESSAGE
(
"spawn ping and exchange messages"
);
client_side
.
spawn
(
make_ping_behavior
,
pong
);
exec_loop
();
CAF_MESSAGE
(
"terminate pong"
);
anon_send_exit
(
spong
,
exit_reason
::
user_shutdown
);
exec_loop
();
}
CAF_TEST
(
authentication_failure
)
{
if
(
!
init
(
true
))
return
;
// server side
auto
pong
=
server_side
.
spawn
(
make_pong_behavior
);
CAF_EXP_THROW
(
port
,
publish
(
pong
,
0
,
local_host
));
CAF_MESSAGE
(
"spawn pong on server"
);
auto
spong
=
server_side
.
spawn
(
make_pong_behavior
);
exec_loop
();
loop_after_next_enqueue
(
server_side
);
CAF_MESSAGE
(
"publish pong"
);
CAF_EXP_THROW
(
port
,
publish
(
spong
,
0
,
local_host
));
exec_loop
();
// client side
CAF_MESSAGE
(
"connect to pong via port "
<<
port
);
loop_after_next_enqueue
(
client_side
);
auto
remote_pong
=
remote_actor
(
client_side
,
local_host
,
port
);
CAF_REQUIRE
(
!
remote_pong
);
anon_send_exit
(
pong
,
exit_reason
::
user_shutdown
);
CAF_CHECK
(
!
remote_pong
);
CAF_MESSAGE
(
"terminate pong"
);
anon_send_exit
(
spong
,
exit_reason
::
user_shutdown
);
exec_loop
();
}
CAF_TEST_FIXTURE_SCOPE_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