static void thread(FiberLocalStorage<int> &fls, Fiber::ptr fiber) { MORDOR_TEST_ASSERT_EQUAL(fls.get(), 0); fls = 3; MORDOR_TEST_ASSERT_EQUAL(fls.get(), 3); fiber->call(); MORDOR_TEST_ASSERT_EQUAL(fls.get(), 3); fls = 5; MORDOR_TEST_ASSERT_EQUAL(fls.get(), 5); }
MORDOR_UNITTEST(PipeStream, destructOnBlockingReader) { std::pair<Stream::ptr, Stream::ptr> pipe = pipeStream(); WorkerPool pool; int sequence = 1; Fiber::ptr f = Fiber::ptr(new Fiber(boost::bind(&destructOnBlockingReader, boost::weak_ptr<Stream>(pipe.first), boost::ref(sequence)))); f->call(); pipe.first.reset(); pool.schedule(f); Buffer output; MORDOR_TEST_ASSERT_EXCEPTION(pipe.second->read(output, 10), BrokenPipeException); MORDOR_TEST_ASSERT_EQUAL(++sequence, 4); }
MORDOR_UNITTEST(PipeStream, destructOnBlockingWriter) { std::pair<Stream::ptr, Stream::ptr> pipe = pipeStream(5); WorkerPool pool; int sequence = 1; Fiber::ptr f = Fiber::ptr(new Fiber(boost::bind(&destructOnBlockingWriter, boost::weak_ptr<Stream>(pipe.first), boost::ref(sequence)))); f->call(); pipe.first.reset(); pool.schedule(f); MORDOR_TEST_ASSERT_EQUAL(pipe.second->write("hello"), 5u); MORDOR_TEST_ASSERT_EQUAL(++sequence, 2); MORDOR_TEST_ASSERT_EXCEPTION(pipe.second->write("world"), BrokenPipeException); MORDOR_TEST_ASSERT_EQUAL(++sequence, 5); }