Commit d89e4b20 authored by Marian Triebe's avatar Marian Triebe

Add new local_group test

parent eb3ecd99
#include "caf/config.hpp" #include <chrono>
#include <map>
#include <list>
#include <mutex>
#include <iostream>
#include <algorithm>
#include "test.hpp" #include "test.hpp"
#include "caf/on.hpp"
#include "caf/all.hpp" #include "caf/all.hpp"
#include "caf/actor.hpp"
#include "caf/abstract_group.hpp"
#include "caf/ref_counted.hpp"
#include "caf/intrusive_ptr.hpp"
using std::cout;
using std::endl;
using std::string;
using namespace caf; using namespace caf;
void testee(event_based_actor* self, int current_value, int final_result) { void testee(event_based_actor* self) {
auto counter = std::make_shared<int>(0);
auto grp = group::get("local", "test");
self->join(grp);
CAF_CHECKPOINT();
self->become( self->become(
[=](int result) { on(atom("msg")) >> [=] {
auto next = result + current_value; CAF_CHECKPOINT();
if (next >= final_result) { ++*counter;
self->quit(); self->leave(grp);
} else { self->send(grp, atom("msg"));
testee(self, next, final_result);
}
}, },
after(std::chrono::seconds(2)) >> [=] { on(atom("over")) >> [=] {
CAF_UNEXPECTED_TOUT(); // this actor should receive only 1 message
self->quit(exit_reason::user_shutdown); CAF_CHECK(*counter == 1);
self->quit();
} }
); );
self->send(grp, atom("msg"));
self->delayed_send(self, std::chrono::seconds(1), atom("over"));
} }
int main() { int main() {
CAF_TEST(test_local_group); CAF_TEST(test_local_group);
/* spawn(testee);
auto foo_group = group::get("local", "foo");
auto master = spawn_in_group(foo_group, testee, 0, 10);
for (int i = 0; i < 5; ++i) {
// spawn five workers and let them join local/foo
spawn_in_group(foo_group, [master] {
become(
[master](int v) {
send(master, v);
self->quit();
}
);
});
}
send(foo_group, 2);
await_all_actors_done(); await_all_actors_done();
shutdown(); shutdown();
*/
return CAF_TEST_RESULT(); return CAF_TEST_RESULT();
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment