MCPcopy Create free account
hub / github.com/bytedance/bolt / TEST_F

Function TEST_F

bolt/expression/tests/ExprTest.cpp:423–455  ·  view source on GitHub ↗

This test shows resolverHook_ is not thread safe

Source from the content-addressed store, hash-verified

421#define INT64N std::optional<int64_t>()
422// This test shows resolverHook_ is not thread safe
423TEST_F(ExprTest, resolverHookNotThreadSafe) {
424 std::vector<std::string> names{"resolverHookNotThreadSafeTest"};
425 std::vector<std::shared_ptr<const Type>> types{BigintType::create()};
426 auto rowTypePtr =
427 std::make_shared<RowType>(std::move(names), std::move(types));
428 std::atomic<int> flag{0};
429
430 std::thread thread1([this]() {
431 core::Expressions::setTypeResolverHook(&dummyIntegerResolver);
432 auto resolver = core::Expressions::getResolverHook();
433 EXPECT_TRUE(resolver({}, nullptr, false)
434 ->kindEquals(dummyIntegerResolver({}, nullptr, false)));
435 std::this_thread::sleep_for(std::chrono::milliseconds(200));
436
437 // resolverHook_ has been updated by thread2
438 resolver = core::Expressions::getResolverHook();
439 EXPECT_FALSE(resolver({}, nullptr, false)
440 ->kindEquals(dummyIntegerResolver({}, nullptr, false)));
441 EXPECT_TRUE(resolver({}, nullptr, false)
442 ->kindEquals(dummyBigIntResolver({}, nullptr, false)));
443 });
444
445 std::thread thread2([this]() {
446 std::this_thread::sleep_for(std::chrono::milliseconds(100));
447 core::Expressions::setTypeResolverHook(&dummyBigIntResolver);
448 auto resolver = core::Expressions::getResolverHook();
449 EXPECT_TRUE(resolver({}, nullptr, false)
450 ->kindEquals(dummyBigIntResolver({}, nullptr, false)));
451 });
452
453 thread1.join();
454 thread2.join();
455}
456
457TEST_F(ExprTest, customResolverHook) {
458 auto expectedExpr =

Callers

nothing calls this directly

Calls 15

resolverClass · 0.85
dummyIntegerResolverFunction · 0.85
dummyBigIntResolverFunction · 0.85
parseExpressionFunction · 0.85
ROWFunction · 0.85
getVectorFunctionFunction · 0.85
compileExpressionFunction · 0.85
wrapInDictionaryFunction · 0.85
makeNullsFunction · 0.85
kindEqualsMethod · 0.80
createFunction · 0.50
registerVectorFunctionFunction · 0.50

Tested by

no test coverage detected