Skip to content

Commit

Permalink
Add test.
Browse files Browse the repository at this point in the history
  • Loading branch information
CPWstatic committed Nov 7, 2019
1 parent 2ef8e03 commit 9780ca6
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/graph/ReturnExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Status ReturnExecutor::prepare() {
}

void ReturnExecutor::execute() {
FLOG_INFO("Executing Return: %s", sentence_->toString().c_str());
DCHECK(onFinish_);
DCHECK(onError_);
DCHECK(sentence_);
Expand Down Expand Up @@ -57,7 +58,13 @@ void ReturnExecutor::execute() {
onError_(std::move(ret).status());
return;
}
auto rows = ret.value();
if (rows.empty()) {
onFinish_(Executor::ProcessControl::kNext);
return;
}
resp_->set_rows(std::move(ret).value());
// Will return if variable has values.
onFinish_(Executor::ProcessControl::kReturn);
}
}
Expand Down
1 change: 1 addition & 0 deletions src/graph/SequentialExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ Status SequentialExecutor::prepare() {
DCHECK(onFinish_);
respExecutorIndex_ = current;
onFinish_(ctr);
break;
}
case Executor::ProcessControl::kNext:
default: {
Expand Down
46 changes: 46 additions & 0 deletions src/graph/test/GoTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -761,5 +761,51 @@ TEST_F(GoTest, is_inCall) {
ASSERT_TRUE(verifyResult(resp, expected));
}
}

TEST_F(GoTest, returnTest) {
{
cpp2::ExecutionResponse resp;
auto *fmt = "$A = GO FROM %ld OVER like YIELD like._dst AS dst;"
"$rA = YIELD $A.* WHERE $A.dst == 123;"
"RETURN $rA IF $rA IS NOT NULL;"
"GO FROM $A.dst OVER serve";
auto query = folly::stringPrintf(fmt, players_["Tim Duncan"].vid());
auto code = client_->execute(query, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);

std::vector<std::string> expectedColNames{
{"serve._dst"}
};
ASSERT_TRUE(verifyColNames(resp, expectedColNames));

std::vector<std::tuple<int64_t>> expected = {
{teams_["Spurs"].vid()},
{teams_["Spurs"].vid()},
{teams_["Hornets"].vid()},
};
ASSERT_TRUE(verifyResult(resp, expected));
}
{
cpp2::ExecutionResponse resp;
auto *fmt = "$A = GO FROM %ld OVER like YIELD like._dst AS dst;"
"$rA = YIELD $A.* WHERE 1 == 1;"
"RETURN $rA IF $rA IS NOT NULL;"
"GO FROM $A.dst OVER serve";
auto query = folly::stringPrintf(fmt, players_["Tim Duncan"].vid());
auto code = client_->execute(query, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);

std::vector<std::string> expectedColNames{
{"$A.dst"}
};
ASSERT_TRUE(verifyColNames(resp, expectedColNames));

std::vector<std::tuple<int64_t>> expected = {
{players_["Tony Parker"].vid()},
{players_["Manu Ginobili"].vid()},
};
ASSERT_TRUE(verifyResult(resp, expected));
}
}
} // namespace graph
} // namespace nebula

0 comments on commit 9780ca6

Please sign in to comment.