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
50c0f8bc
Commit
50c0f8bc
authored
Jul 13, 2020
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add unit tests for the default exception handler
parent
9d542932
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
7 deletions
+30
-7
libcaf_core/test/custom_exception_handler.cpp
libcaf_core/test/custom_exception_handler.cpp
+30
-7
No files found.
libcaf_core/test/custom_exception_handler.cpp
View file @
50c0f8bc
...
@@ -28,21 +28,24 @@ using namespace caf;
...
@@ -28,21 +28,24 @@ using namespace caf;
# error "building unit test for exception handlers in no-exceptions build"
# error "building unit test for exception handlers in no-exceptions build"
#endif
#endif
behavior
testee
()
{
return
{
[](
const
std
::
string
&
)
{
throw
std
::
runtime_error
(
"whatever"
);
},
};
}
class
exception_testee
:
public
event_based_actor
{
class
exception_testee
:
public
event_based_actor
{
public:
public:
~
exception_testee
()
override
;
exception_testee
(
actor_config
&
cfg
)
:
event_based_actor
(
cfg
)
{
exception_testee
(
actor_config
&
cfg
)
:
event_based_actor
(
cfg
)
{
set_exception_handler
([](
std
::
exception_ptr
&
)
->
error
{
set_exception_handler
([](
std
::
exception_ptr
&
)
->
error
{
return
exit_reason
::
remote_link_unreachable
;
return
exit_reason
::
remote_link_unreachable
;
});
});
}
}
~
exception_testee
()
override
;
behavior
make_behavior
()
override
{
behavior
make_behavior
()
override
{
return
{
return
testee
();
[](
const
std
::
string
&
)
{
throw
std
::
runtime_error
(
"whatever"
);
}
};
}
}
};
};
...
@@ -50,7 +53,27 @@ exception_testee::~exception_testee() {
...
@@ -50,7 +53,27 @@ exception_testee::~exception_testee() {
// avoid weak-vtables warning
// avoid weak-vtables warning
}
}
CAF_TEST
(
test_custom_exception_handler
)
{
CAF_TEST
(
the
default
exception
handler
includes
the
error
message
)
{
using
std
::
string
;
actor_system_config
cfg
;
actor_system
system
{
cfg
};
scoped_actor
self
{
system
};
auto
aut
=
self
->
spawn
(
testee
);
self
->
request
(
aut
,
infinite
,
"hello world"
)
.
receive
(
//
[]
{
CAF_FAIL
(
"unexpected response"
);
},
[](
const
error
&
err
)
{
auto
msg
=
err
.
context
();
if
(
auto
view
=
make_typed_message_view
<
string
,
string
>
(
msg
))
{
CAF_CHECK_EQUAL
(
get
<
0
>
(
view
),
"std.runtime_error"
);
CAF_CHECK_EQUAL
(
get
<
1
>
(
view
),
"whatever"
);
}
else
{
CAF_FAIL
(
"unexpected error contest: "
<<
err
.
context
());
}
});
}
CAF_TEST
(
actors
can
override
the
default
exception
handler
)
{
actor_system_config
cfg
;
actor_system_config
cfg
;
actor_system
system
{
cfg
};
actor_system
system
{
cfg
};
auto
handler
=
[](
std
::
exception_ptr
&
eptr
)
->
error
{
auto
handler
=
[](
std
::
exception_ptr
&
eptr
)
->
error
{
...
...
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