Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 34FA6200ACA for ; Thu, 19 May 2016 04:54:44 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 3389B160A15; Thu, 19 May 2016 02:54:44 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 539AF160A00 for ; Thu, 19 May 2016 04:54:43 +0200 (CEST) Received: (qmail 10818 invoked by uid 500); 19 May 2016 02:54:42 -0000 Mailing-List: contact commits-help@hawq.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@hawq.incubator.apache.org Delivered-To: mailing list commits@hawq.incubator.apache.org Received: (qmail 10808 invoked by uid 99); 19 May 2016 02:54:42 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 19 May 2016 02:54:42 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id 20770180501 for ; Thu, 19 May 2016 02:54:42 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -3.221 X-Spam-Level: X-Spam-Status: No, score=-3.221 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_DNSWL_HI=-5, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RP_MATCHES_RCVD=-0.001] autolearn=disabled Received: from mx2-lw-us.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id 8BRPuiiTyLbG for ; Thu, 19 May 2016 02:54:41 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx2-lw-us.apache.org (ASF Mail Server at mx2-lw-us.apache.org) with SMTP id A5B9F5F1B8 for ; Thu, 19 May 2016 02:54:40 +0000 (UTC) Received: (qmail 10805 invoked by uid 99); 19 May 2016 02:54:40 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 19 May 2016 02:54:40 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 187E8DFB73; Thu, 19 May 2016 02:54:40 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: ztao1987@apache.org To: commits@hawq.incubator.apache.org Message-Id: <4dc20d0aea3645a1a536de25925849fd@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: incubator-hawq git commit: HAWQ-740. Fix bug in SQLUtility. Date: Thu, 19 May 2016 02:54:40 +0000 (UTC) archived-at: Thu, 19 May 2016 02:54:44 -0000 Repository: incubator-hawq Updated Branches: refs/heads/master 025eecbad -> 3c2419bcc HAWQ-740. Fix bug in SQLUtility. Project: http://git-wip-us.apache.org/repos/asf/incubator-hawq/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-hawq/commit/3c2419bc Tree: http://git-wip-us.apache.org/repos/asf/incubator-hawq/tree/3c2419bc Diff: http://git-wip-us.apache.org/repos/asf/incubator-hawq/diff/3c2419bc Branch: refs/heads/master Commit: 3c2419bcc51a55cf1fd8445fbd41b046c2b50ab3 Parents: 025eecb Author: ztao1987 Authored: Thu May 19 10:53:29 2016 +0800 Committer: ztao1987 Committed: Thu May 19 10:53:29 2016 +0800 ---------------------------------------------------------------------- src/test/feature/lib/sql-util.cpp | 50 +++++++++++++++++++++++----------- src/test/feature/lib/sql-util.h | 8 ++++-- 2 files changed, 40 insertions(+), 18 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/3c2419bc/src/test/feature/lib/sql-util.cpp ---------------------------------------------------------------------- diff --git a/src/test/feature/lib/sql-util.cpp b/src/test/feature/lib/sql-util.cpp index 61b3d87..6283adb 100644 --- a/src/test/feature/lib/sql-util.cpp +++ b/src/test/feature/lib/sql-util.cpp @@ -1,5 +1,6 @@ #include "sql-util.h" +#include #include #include #include @@ -16,22 +17,26 @@ SQLUtility::SQLUtility() test_info(::testing::UnitTest::GetInstance()->current_test_info()) { schemaName = std::string(test_info->test_case_name()) + "_" + test_info->name(); - conn->runSQLCommand("DROP SCHEMA IF EXISTS " + schemaName + " CASCADE"); - conn->runSQLCommand("CREATE SCHEMA " + schemaName); + exec("DROP SCHEMA IF EXISTS " + schemaName + " CASCADE"); + exec("CREATE SCHEMA " + schemaName); } SQLUtility::~SQLUtility() { if (!test_info->result()->Failed()) - conn->runSQLCommand("DROP SCHEMA " + schemaName + " CASCADE"); + exec("DROP SCHEMA " + schemaName + " CASCADE"); } -void SQLUtility::execute(const std::string &sql) { - EXPECT_EQ((conn->runSQLCommand("SET SEARCH_PATH=" + schemaName + ";" + sql)) - .getLastStatus(), - 0) +void SQLUtility::exec(const std::string &sql) { + EXPECT_EQ((conn->runSQLCommand(sql)).getLastStatus(), 0) << conn->getLastResult(); } +void SQLUtility::execute(const std::string &sql, bool check) { + conn->runSQLCommand("SET SEARCH_PATH=" + schemaName + ";" + sql); + EXPECT_NE(conn.get(), nullptr); + if (check) EXPECT_EQ(conn->getLastStatus(), 0) << conn->getLastResult(); +} + void SQLUtility::query(const std::string &sql, int expectNum) { const PSQLQueryResult &result = executeQuery(sql); ASSERT_FALSE(result.isError()) << result.getErrorMessage(); @@ -69,22 +74,27 @@ void SQLUtility::execSQLFile(const std::string &sqlFile, const std::string newSqlFile = generateSQLFile(sqlFile); // outFile is located in the same folder with ansFile - std::string outFile = fp.path + "/" + fp.fileBaseName + ".out"; - conn->setOutputFile(outFile); + std::string outFileAbsPath = fp.path + "/" + fp.fileBaseName + ".out"; + conn->setOutputFile(outFileAbsPath); EXPECT_EQ(conn->runSQLFile(newSqlFile).getLastStatus(), 0); conn->resetOutput(); - if (remove(newSqlFile.c_str())) - ASSERT_TRUE(false) << "Error deleting file " << newSqlFile; - EXPECT_FALSE(conn->checkDiff(ansFile, outFile, true)); + EXPECT_FALSE(conn->checkDiff(ansFileAbsPath, outFileAbsPath, true)); + if (conn->checkDiff(ansFileAbsPath, outFileAbsPath, true) == false) { + // no diff, continue to delete the generated sql file + if (remove(newSqlFile.c_str())) + ASSERT_TRUE(false) << "Error deleting file " << newSqlFile; + } else { + EXPECT_FALSE(true); + } } std::unique_ptr SQLUtility::getConnection() { std::string user = HAWQ_USER; - if(user == ""){ + if (user.empty()) { struct passwd *pw; uid_t uid = geteuid(); pw = getpwuid(uid); - user.assign(pw->pw_name);; + user.assign(pw->pw_name); } std::unique_ptr psql( new PSQL(HAWQ_DB, HAWQ_HOST, HAWQ_PORT, user, HAWQ_PASSWORD)); @@ -125,8 +135,16 @@ const PSQLQueryResult &SQLUtility::executeQuery(const std::string &sql) { PSQL *SQLUtility::getPSQL() const { return conn.get(); } std::string SQLUtility::getTestRootPath() const { - FilePath fp = splitFilePath(__FILE__); - return splitFilePath(__FILE__).path + "/.."; + int ret; + pid_t pid; + char pathbuf[PROC_PIDPATHINFO_MAXSIZE]; + + pid = getpid(); + ret = proc_pidpath(pid, pathbuf, sizeof(pathbuf)); + if (ret <= 0) + EXPECT_TRUE(false) << "PID " << pid << ": proc_pidpath () " + << strerror(errno); + return splitFilePath(pathbuf).path; } FilePath SQLUtility::splitFilePath(const std::string &filePath) const { http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/3c2419bc/src/test/feature/lib/sql-util.h ---------------------------------------------------------------------- diff --git a/src/test/feature/lib/sql-util.h b/src/test/feature/lib/sql-util.h index 8070d3f..e9455d7 100644 --- a/src/test/feature/lib/sql-util.h +++ b/src/test/feature/lib/sql-util.h @@ -26,7 +26,7 @@ class SQLUtility { // Execute sql command // @param sql The given sql command // @return void - void execute(const std::string &sql); + void execute(const std::string &sql, bool check = true); // Execute query command and check the rowCount // @param sql The given query command @@ -50,12 +50,16 @@ class SQLUtility { // @return PSQL raw pointer PSQL *getPSQL() const; + // Get test root dir abs path + // @return path string + std::string getTestRootPath() const; + private: std::unique_ptr getConnection(); const std::string generateSQLFile(const std::string &sqlFile); const PSQLQueryResult &executeQuery(const std::string &sql); - std::string getTestRootPath() const; FilePath splitFilePath(const std::string &filePath) const; + void exec(const std::string &sql); private: std::string schemaName;