MCPcopy Create free account
hub / github.com/apache/arrow / ASSERT_OK_AND_ASSIGN

Function ASSERT_OK_AND_ASSIGN

cpp/src/arrow/util/thread_pool_test.cc:856–1050  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

854 // Reference passing
855 std::string s = "foo";
856 ASSERT_OK_AND_ASSIGN(auto fut,
857 pool->Submit(inplace_add<std::string>, std::ref(s), "bar"));
858 ASSERT_OK_AND_EQ("foobar", fut.result());
859 ASSERT_EQ(s, "foobar");
860 }
861 {
862 // `void` return type
863 ASSERT_OK_AND_ASSIGN(auto fut, pool->Submit(SleepFor, 0.001));
864 ASSERT_OK(fut.status());
865 }
866}
867
868TEST_F(TestThreadPool, SubmitWithStopToken) {
869 auto pool = this->MakeThreadPool(3);
870 {
871 StopSource stop_source;
872 ASSERT_OK_AND_ASSIGN(Future<int> fut,
873 pool->Submit(stop_source.token(), add<int>, 4, 5));
874 Result<int> res = fut.result();
875 ASSERT_OK_AND_EQ(9, res);
876 }
877}
878
879TEST_F(TestThreadPool, SubmitWithStopTokenCancelled) {
880 auto pool = this->MakeThreadPool(3);
881 {
882 const int n_futures = 100;
883 StopSource stop_source;
884 StopToken stop_token = stop_source.token();
885 std::vector<Future<int>> futures;
886 for (int i = 0; i < n_futures; ++i) {
887 ASSERT_OK_AND_ASSIGN(
888 auto fut, pool->Submit(stop_token, slow_add<int>, 0.01 /*seconds*/, i, 1));
889 futures.push_back(std::move(fut));
890 }
891 SleepFor(0.05); // Let some work finish
892 stop_source.RequestStop();
893 int n_success = 0;
894 int n_cancelled = 0;
895 for (int i = 0; i < n_futures; ++i) {
896 Result<int> res = futures[i].result();
897 if (res.ok()) {
898 ASSERT_EQ(i + 1, *res);
899 ++n_success;
900 } else {
901 ASSERT_RAISES(Cancelled, res);
902 ++n_cancelled;
903 }
904 }
905 ASSERT_GT(n_success, 0);
906 ASSERT_GT(n_cancelled, 0);
907 }
908}
909
910// Test fork safety on Unix
911
912#if !(defined(_WIN32) || defined(ARROW_VALGRIND) || defined(ADDRESS_SANITIZER) || \
913 defined(THREAD_SANITIZER))

Callers 15

BitmapFromVectorFunction · 0.70
TestAlignedMethod · 0.70
TestUnalignedMethod · 0.70
TESTFunction · 0.70
DoBitmapVisitAndWriteFunction · 0.70
CheckCodecRoundtripFunction · 0.70
CheckStreamingCompressorFunction · 0.70
CheckStreamingRoundtripFunction · 0.70
TEST_PFunction · 0.70
TESTFunction · 0.70
TESTFunction · 0.70

Calls 15

SleepForFunction · 0.85
AssertChildExitFunction · 0.85
DeferNotOkFunction · 0.85
MakeThreadPoolMethod · 0.80
tokenMethod · 0.80
push_backMethod · 0.80
RequestStopMethod · 0.80
emplace_backMethod · 0.80
TEST_FFunction · 0.70
resultMethod · 0.45
ShutdownMethod · 0.45
okMethod · 0.45

Tested by

no test coverage detected