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
80cacfe4
Commit
80cacfe4
authored
Jan 21, 2023
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add test suite for flow::op::cell
parent
d8dfff00
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
179 additions
and
2 deletions
+179
-2
libcaf_core/CMakeLists.txt
libcaf_core/CMakeLists.txt
+1
-0
libcaf_core/caf/flow/observer.hpp
libcaf_core/caf/flow/observer.hpp
+7
-0
libcaf_core/caf/flow/subscription.hpp
libcaf_core/caf/flow/subscription.hpp
+4
-0
libcaf_core/test/flow/broadcaster.cpp
libcaf_core/test/flow/broadcaster.cpp
+0
-2
libcaf_core/test/flow/op/cell.cpp
libcaf_core/test/flow/op/cell.cpp
+167
-0
No files found.
libcaf_core/CMakeLists.txt
View file @
80cacfe4
...
@@ -294,6 +294,7 @@ caf_add_component(
...
@@ -294,6 +294,7 @@ caf_add_component(
flow.mixed
flow.mixed
flow.never
flow.never
flow.observe_on
flow.observe_on
flow.op.cell
flow.prefix_and_tail
flow.prefix_and_tail
flow.publish
flow.publish
flow.single
flow.single
...
...
libcaf_core/caf/flow/observer.hpp
View file @
80cacfe4
...
@@ -570,6 +570,13 @@ public:
...
@@ -570,6 +570,13 @@ public:
}
}
}
}
void
unsubscribe
()
{
if
(
sub
)
{
sub
.
dispose
();
state
=
observer_state
::
idle
;
}
}
bool
idle
()
const
noexcept
{
bool
idle
()
const
noexcept
{
return
state
==
observer_state
::
idle
;
return
state
==
observer_state
::
idle
;
}
}
...
...
libcaf_core/caf/flow/subscription.hpp
View file @
80cacfe4
...
@@ -172,6 +172,10 @@ public:
...
@@ -172,6 +172,10 @@ public:
return
disposable
{
std
::
move
(
pimpl_
)};
return
disposable
{
std
::
move
(
pimpl_
)};
}
}
bool
disposed
()
const
noexcept
{
return
!
pimpl_
||
pimpl_
->
disposed
();
}
// -- swapping ---------------------------------------------------------------
// -- swapping ---------------------------------------------------------------
void
swap
(
subscription
&
other
)
noexcept
{
void
swap
(
subscription
&
other
)
noexcept
{
...
...
libcaf_core/test/flow/broadcaster.cpp
View file @
80cacfe4
...
@@ -11,8 +11,6 @@
...
@@ -11,8 +11,6 @@
#include "caf/flow/observable_builder.hpp"
#include "caf/flow/observable_builder.hpp"
#include "caf/flow/scoped_coordinator.hpp"
#include "caf/flow/scoped_coordinator.hpp"
namespace
caf
::
flow
{}
// namespace caf::flow
using
namespace
caf
;
using
namespace
caf
;
namespace
{
namespace
{
...
...
libcaf_core/test/flow/op/cell.cpp
0 → 100644
View file @
80cacfe4
// This file is part of CAF, the C++ Actor Framework. See the file LICENSE in
// the main distribution directory for license terms and copyright or visit
// https://github.com/actor-framework/actor-framework/blob/master/LICENSE.
#define CAF_SUITE flow.op.cell
#include "caf/flow/op/cell.hpp"
#include "core-test.hpp"
#include "caf/flow/observable.hpp"
#include "caf/flow/scoped_coordinator.hpp"
using
namespace
caf
;
namespace
{
using
int_cell
=
flow
::
op
::
cell
<
int
>
;
using
int_cell_ptr
=
intrusive_ptr
<
int_cell
>
;
struct
fixture
:
test_coordinator_fixture
<>
{
flow
::
scoped_coordinator_ptr
ctx
=
flow
::
make_scoped_coordinator
();
int_cell_ptr
make_cell
()
{
return
make_counted
<
int_cell
>
(
ctx
.
get
());
}
flow
::
observable
<
int
>
lift
(
int_cell_ptr
cell
)
{
return
flow
::
observable
<
int
>
{
cell
};
}
};
}
// namespace
BEGIN_FIXTURE_SCOPE
(
fixture
)
SCENARIO
(
"a null cell emits zero items"
)
{
GIVEN
(
"an integer cell with an observer"
)
{
WHEN
(
"calling set_null on the cell"
)
{
THEN
(
"the observer receives the completed event"
)
{
auto
uut
=
make_cell
();
auto
snk
=
flow
::
make_passive_observer
<
int
>
();
lift
(
uut
).
subscribe
(
snk
->
as_observer
());
REQUIRE
(
snk
->
subscribed
());
snk
->
sub
.
request
(
128
);
ctx
->
run
();
REQUIRE
(
snk
->
subscribed
());
uut
->
set_null
();
ctx
->
run
();
CHECK
(
snk
->
completed
());
CHECK
(
snk
->
buf
.
empty
());
}
}
}
GIVEN
(
"an integer cell without on bserver"
)
{
WHEN
(
"calling set_null on the cell"
)
{
THEN
(
"observers receive completed events immediately after subscribing"
)
{
auto
uut
=
make_cell
();
uut
->
set_null
();
auto
snk
=
flow
::
make_passive_observer
<
int
>
();
lift
(
uut
).
subscribe
(
snk
->
as_observer
());
REQUIRE
(
snk
->
subscribed
());
snk
->
sub
.
request
(
128
);
ctx
->
run
();
CHECK
(
snk
->
completed
());
CHECK
(
snk
->
buf
.
empty
());
}
}
}
}
SCENARIO
(
"a cell with a value emits exactly one item"
)
{
GIVEN
(
"an integer cell with an observer"
)
{
WHEN
(
"calling set_value on the cell"
)
{
THEN
(
"the observer receives on_next and then on_complete"
)
{
auto
uut
=
make_cell
();
auto
snk
=
flow
::
make_passive_observer
<
int
>
();
lift
(
uut
).
subscribe
(
snk
->
as_observer
());
REQUIRE
(
snk
->
subscribed
());
snk
->
sub
.
request
(
128
);
ctx
->
run
();
REQUIRE
(
snk
->
subscribed
());
uut
->
set_value
(
42
);
ctx
->
run
();
CHECK
(
snk
->
completed
());
CHECK_EQ
(
snk
->
buf
,
std
::
vector
<
int
>
{
42
});
}
}
WHEN
(
"disposing the subscription before calling set_value on the cell"
)
{
THEN
(
"the observer does not receive the item"
)
{
auto
uut
=
make_cell
();
auto
snk
=
flow
::
make_passive_observer
<
int
>
();
lift
(
uut
).
subscribe
(
snk
->
as_observer
());
REQUIRE
(
snk
->
subscribed
());
snk
->
request
(
128
);
ctx
->
run
();
// Normally, we'd call snk->unsubscribe() here. However, that nulls the
// subscription. We want the sub.disposed() call below actually call
// cell_sub::disposed() to have coverage on that member function.
snk
->
sub
.
ptr
()
->
dispose
();
snk
->
state
=
flow
::
observer_state
::
idle
;
ctx
->
run
();
CHECK
(
snk
->
sub
.
disposed
());
CHECK
(
snk
->
idle
());
uut
->
set_value
(
42
);
ctx
->
run
();
CHECK
(
snk
->
idle
());
CHECK
(
snk
->
buf
.
empty
());
}
}
}
GIVEN
(
"an integer cell without on bserver"
)
{
WHEN
(
"calling set_null on the cell"
)
{
THEN
(
"the observer receives on_next and then on_complete immediately"
)
{
auto
uut
=
make_cell
();
uut
->
set_value
(
42
);
auto
snk
=
flow
::
make_passive_observer
<
int
>
();
lift
(
uut
).
subscribe
(
snk
->
as_observer
());
REQUIRE
(
snk
->
subscribed
());
snk
->
sub
.
request
(
128
);
ctx
->
run
();
CHECK
(
snk
->
completed
());
CHECK_EQ
(
snk
->
buf
,
std
::
vector
<
int
>
{
42
});
}
}
}
}
SCENARIO
(
"a failed cell emits zero item"
)
{
GIVEN
(
"an integer cell with an observer"
)
{
WHEN
(
"calling set_error on the cell"
)
{
THEN
(
"the observer receives on_error"
)
{
auto
uut
=
make_cell
();
auto
snk
=
flow
::
make_passive_observer
<
int
>
();
lift
(
uut
).
subscribe
(
snk
->
as_observer
());
REQUIRE
(
snk
->
subscribed
());
snk
->
sub
.
request
(
128
);
ctx
->
run
();
REQUIRE
(
snk
->
subscribed
());
uut
->
set_error
(
sec
::
runtime_error
);
ctx
->
run
();
CHECK
(
snk
->
aborted
());
CHECK
(
snk
->
buf
.
empty
());
CHECK_EQ
(
snk
->
err
,
sec
::
runtime_error
);
}
}
}
GIVEN
(
"an integer cell without on bserver"
)
{
WHEN
(
"calling set_error on the cell"
)
{
THEN
(
"the observer receives on_error immediately when subscribing"
)
{
auto
uut
=
make_cell
();
uut
->
set_error
(
sec
::
runtime_error
);
auto
snk
=
flow
::
make_passive_observer
<
int
>
();
lift
(
uut
).
subscribe
(
snk
->
as_observer
());
REQUIRE
(
snk
->
subscribed
());
snk
->
sub
.
request
(
128
);
ctx
->
run
();
CHECK
(
snk
->
aborted
());
CHECK
(
snk
->
buf
.
empty
());
CHECK_EQ
(
snk
->
err
,
sec
::
runtime_error
);
}
}
}
}
END_FIXTURE_SCOPE
()
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