Skip to content

Commit

Permalink
Correct the infinite loop when go zero steps in cycle. (vesoft-inc#2101)
Browse files Browse the repository at this point in the history
* Correct the forever loop when go zero steps in cycle.

* Note the testing case.

* Correct.

Co-authored-by: dutor <440396+dutor@users.noreply.github.com>
  • Loading branch information
Shylock-Hg and dutor authored May 19, 2020
1 parent 7a0152b commit 68d5ed8
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/graph/GoExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ void GoExecutor::execute() {
return;
}

if (steps_ == 0) {
// #2100
// TODO(shylock) unify the steps checking
onEmptyInputs();
return;
}

status = setupStarts();
if (!status.ok()) {
doError(std::move(status));
Expand Down
31 changes: 31 additions & 0 deletions src/graph/test/GoTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2369,6 +2369,37 @@ TEST_P(GoTest, Contains) {
}
}

TEST_P(GoTest, ZeroStep) {
// Zero step
{
// #2100
// A cycle traversal
cpp2::ExecutionResponse resp;
auto *fmt = "GO 0 STEPS FROM %ld OVER serve BIDIRECT";
auto query = folly::stringPrintf(fmt, players_["Tim Duncan"].vid());
auto code = client_->execute(query, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);

// Empty response
std::vector<std::tuple<int64_t>> expected = {
};
ASSERT_TRUE(verifyResult(resp, expected));
}

{
// a normal traversal
cpp2::ExecutionResponse resp;
auto *fmt = "GO 0 STEPS FROM %ld 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::tuple<int64_t>> expected = {
};
ASSERT_TRUE(verifyResult(resp, expected));
}
}

INSTANTIATE_TEST_CASE_P(IfPushdownFilter, GoTest, ::testing::Bool());
} // namespace graph
} // namespace nebula
12 changes: 12 additions & 0 deletions src/parser/test/ParserTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,18 @@
namespace nebula {

TEST(Parser, Go) {
{
GQLParser parser;
std::string query = "GO 0 STEPS FROM 1 OVER friend";
auto result = parser.parse(query);
ASSERT_TRUE(result.ok()) << result.status();
}
{
GQLParser parser;
std::string query = "GO -1 STEPS FROM 1 OVER friend";
auto result = parser.parse(query);
ASSERT_FALSE(result.ok()) << result.status();
}
{
GQLParser parser;
std::string query = "GO FROM 1 OVER friend";
Expand Down

0 comments on commit 68d5ed8

Please sign in to comment.