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:887–1081  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

885 // Reference passing
886 std::string s = "foo";
887 ASSERT_OK_AND_ASSIGN(auto fut,
888 pool->Submit(inplace_add<std::string>, std::ref(s), "bar"));
889 ASSERT_OK_AND_EQ("foobar", fut.result());
890 ASSERT_EQ(s, "foobar");
891 }
892 {
893 // `void` return type
894 ASSERT_OK_AND_ASSIGN(auto fut, pool->Submit(SleepFor, 0.001));
895 ASSERT_OK(fut.status());
896 }
897}
898
899TEST_F(TestThreadPool, SubmitWithStopToken) {
900 auto pool = this->MakeThreadPool(3);
901 {
902 StopSource stop_source;
903 ASSERT_OK_AND_ASSIGN(Future<int> fut,
904 pool->Submit(stop_source.token(), add<int>, 4, 5));
905 Result<int> res = fut.result();
906 ASSERT_OK_AND_EQ(9, res);
907 }
908}
909
910TEST_F(TestThreadPool, SubmitWithStopTokenCancelled) {
911 auto pool = this->MakeThreadPool(3);
912 {
913 const int n_futures = 100;
914 StopSource stop_source;
915 StopToken stop_token = stop_source.token();
916 std::vector<Future<int>> futures;
917 for (int i = 0; i < n_futures; ++i) {
918 ASSERT_OK_AND_ASSIGN(
919 auto fut, pool->Submit(stop_token, slow_add<int>, 0.01 /*seconds*/, i, 1));
920 futures.push_back(std::move(fut));
921 }
922 SleepFor(0.05); // Let some work finish
923 stop_source.RequestStop();
924 int n_success = 0;
925 int n_cancelled = 0;
926 for (int i = 0; i < n_futures; ++i) {
927 Result<int> res = futures[i].result();
928 if (res.ok()) {
929 ASSERT_EQ(i + 1, *res);
930 ++n_success;
931 } else {
932 ASSERT_RAISES(Cancelled, res);
933 ++n_cancelled;
934 }
935 }
936 ASSERT_GT(n_success, 0);
937 ASSERT_GT(n_cancelled, 0);
938 }
939}
940
941// Test fork safety on Unix
942
943#if !(defined(_WIN32) || defined(ARROW_VALGRIND) || defined(ADDRESS_SANITIZER) || \
944 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