You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kyuubi.apache.org by ch...@apache.org on 2022/09/08 08:03:56 UTC
[incubator-kyuubi] branch master updated: [KYUUBI #3445] Flaky Test: Temp view should be deleted after test suite
This is an automated email from the ASF dual-hosted git repository.
chengpan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-kyuubi.git
The following commit(s) were added to refs/heads/master by this push:
new abbb06f9d [KYUUBI #3445] Flaky Test: Temp view should be deleted after test suite
abbb06f9d is described below
commit abbb06f9dad81ae893172f2f77a95e7ebba1b143
Author: yikf <yi...@gmail.com>
AuthorDate: Thu Sep 8 08:01:04 2022 +0000
[KYUUBI #3445] Flaky Test: Temp view should be deleted after test suite
### _Why are the changes needed?_
Fix https://github.com/apache/incubator-kyuubi/issues/3445
temp view should be deleted after test suite, otherwise, some tests which purpose to test show tables will be failure
### _How was this patch tested?_
- [ ] Add some test cases that check the changes thoroughly including negative and positive cases if possible
- [ ] Add screenshots for manual tests if appropriate
- [ ] [Run test](https://kyuubi.apache.org/docs/latest/develop_tools/testing.html#running-tests) locally before make a pull request
Closes #3446 from Yikf/flaky-authz-test.
Closes #3445
4f543704 [yikf] clean view temp resource
Authored-by: yikf <yi...@gmail.com>
Signed-off-by: Cheng Pan <ch...@apache.org>
---
.../authz/ranger/RangerSparkExtensionSuite.scala | 71 ++++++++++++++++++----
1 file changed, 59 insertions(+), 12 deletions(-)
diff --git a/extensions/spark/kyuubi-spark-authz/src/test/scala/org/apache/kyuubi/plugin/spark/authz/ranger/RangerSparkExtensionSuite.scala b/extensions/spark/kyuubi-spark-authz/src/test/scala/org/apache/kyuubi/plugin/spark/authz/ranger/RangerSparkExtensionSuite.scala
index 6f7bbb040..1095a7b7c 100644
--- a/extensions/spark/kyuubi-spark-authz/src/test/scala/org/apache/kyuubi/plugin/spark/authz/ranger/RangerSparkExtensionSuite.scala
+++ b/extensions/spark/kyuubi-spark-authz/src/test/scala/org/apache/kyuubi/plugin/spark/authz/ranger/RangerSparkExtensionSuite.scala
@@ -25,6 +25,7 @@ import scala.util.Try
import org.apache.commons.codec.digest.DigestUtils
import org.apache.hadoop.security.UserGroupInformation
import org.apache.spark.sql.{Row, SparkSessionExtensions}
+import org.apache.spark.sql.catalyst.analysis.NoSuchTableException
import org.apache.spark.sql.catalyst.catalog.HiveTableRelation
import org.apache.spark.sql.catalyst.plans.logical.Statistics
import org.apache.spark.sql.execution.columnar.InMemoryRelation
@@ -80,6 +81,42 @@ abstract class RangerSparkExtensionSuite extends AnyFunSuite
}
}
+ /**
+ * Drops temporary view `viewNames` after calling `f`.
+ */
+ protected def withTempView(viewNames: String*)(f: => Unit): Unit = {
+ try {
+ f
+ } finally {
+ viewNames.foreach { viewName =>
+ try spark.catalog.dropTempView(viewName)
+ catch {
+ // If the test failed part way, we don't want to mask the failure by failing to remove
+ // temp views that never got created.
+ case _: NoSuchTableException =>
+ }
+ }
+ }
+ }
+
+ /**
+ * Drops global temporary view `viewNames` after calling `f`.
+ */
+ protected def withGlobalTempView(viewNames: String*)(f: => Unit): Unit = {
+ try {
+ f
+ } finally {
+ viewNames.foreach { viewName =>
+ try spark.catalog.dropGlobalTempView(viewName)
+ catch {
+ // If the test failed part way, we don't want to mask the failure by failing to remove
+ // global temp views that never got created.
+ case _: NoSuchTableException =>
+ }
+ }
+ }
+ }
+
test("[KYUUBI #3226] RuleAuthorization: Should check privileges once only.") {
val logicalPlan = doAs("admin", sql("SHOW TABLES").queryExecution.logical)
val rule = new RuleAuthorization(spark)
@@ -529,21 +566,31 @@ abstract class RangerSparkExtensionSuite extends AnyFunSuite
test("[KYUUBI #3343] pass temporary view creation") {
val tempView = "temp_view"
val globalTempView = "global_temp_view"
- doAs("denyuser", sql(s"CREATE TEMPORARY VIEW $tempView AS select * from values(1)"))
- doAs(
- "denyuser",
- sql(s"CREATE OR REPLACE TEMPORARY VIEW $tempView" +
- s" AS select * from values(1)"))
+ withTempView(tempView) {
+ doAs(
+ "denyuser",
+ assert(Try(sql(s"CREATE TEMPORARY VIEW $tempView AS select * from values(1)")).isSuccess))
- doAs(
- "denyuser",
- sql(s"CREATE GLOBAL TEMPORARY VIEW $globalTempView AS SELECT * FROM values(1)"))
+ doAs(
+ "denyuser",
+ Try(sql(s"CREATE OR REPLACE TEMPORARY VIEW $tempView" +
+ s" AS select * from values(1)")).isSuccess)
+ }
- doAs(
- "denyuser",
- sql(s"CREATE OR REPLACE GLOBAL TEMPORARY VIEW $globalTempView" +
- s" AS select * from values(1)"))
+ withGlobalTempView(globalTempView) {
+ doAs(
+ "denyuser",
+ Try(
+ sql(
+ s"CREATE GLOBAL TEMPORARY VIEW $globalTempView AS SELECT * FROM values(1)")).isSuccess)
+
+ doAs(
+ "denyuser",
+ Try(sql(s"CREATE OR REPLACE GLOBAL TEMPORARY VIEW $globalTempView" +
+ s" AS select * from values(1)")).isSuccess)
+ }
+ doAs("admin", assert(sql("show tables from global_temp").collect().length == 0))
}
}