-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-31756][WEBUI][3.0] Add real headless browser support for UI test #28702
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
sarutak
wants to merge
1
commit into
apache:branch-3.0
from
sarutak:real-headless-browser-support-3.0
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
common/tags/src/test/java/org/apache/spark/tags/ChromeUITest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.spark.tags; | ||
|
|
||
| import java.lang.annotation.*; | ||
|
|
||
| import org.scalatest.TagAnnotation; | ||
|
|
||
| @TagAnnotation | ||
| @Retention(RetentionPolicy.RUNTIME) | ||
| @Target({ElementType.METHOD, ElementType.TYPE}) | ||
| public @interface ChromeUITest { } |
49 changes: 49 additions & 0 deletions
49
core/src/test/scala/org/apache/spark/ui/ChromeUISeleniumSuite.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.spark.ui | ||
|
|
||
| import org.openqa.selenium.WebDriver | ||
| import org.openqa.selenium.chrome.{ChromeDriver, ChromeOptions} | ||
|
|
||
| import org.apache.spark.tags.ChromeUITest | ||
|
|
||
| /** | ||
| * Selenium tests for the Spark Web UI with Chrome. | ||
| */ | ||
| @ChromeUITest | ||
| class ChromeUISeleniumSuite extends RealBrowserUISeleniumSuite("webdriver.chrome.driver") { | ||
|
|
||
| override var webDriver: WebDriver = _ | ||
|
|
||
| override def beforeAll(): Unit = { | ||
| super.beforeAll() | ||
| val chromeOptions = new ChromeOptions | ||
| chromeOptions.addArguments("--headless", "--disable-gpu") | ||
| webDriver = new ChromeDriver(chromeOptions) | ||
| } | ||
|
|
||
| override def afterAll(): Unit = { | ||
| try { | ||
| if (webDriver != null) { | ||
| webDriver.quit() | ||
| } | ||
| } finally { | ||
| super.afterAll() | ||
| } | ||
| } | ||
| } |
109 changes: 109 additions & 0 deletions
109
core/src/test/scala/org/apache/spark/ui/RealBrowserUISeleniumSuite.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.spark.ui | ||
|
|
||
| import org.openqa.selenium.{By, WebDriver} | ||
| import org.scalatest._ | ||
| import org.scalatest.concurrent.Eventually._ | ||
| import org.scalatest.time.SpanSugar._ | ||
| import org.scalatestplus.selenium.WebBrowser | ||
|
|
||
| import org.apache.spark._ | ||
| import org.apache.spark.LocalSparkContext.withSpark | ||
| import org.apache.spark.internal.config.MEMORY_OFFHEAP_SIZE | ||
| import org.apache.spark.internal.config.UI.{UI_ENABLED, UI_KILL_ENABLED, UI_PORT} | ||
| import org.apache.spark.util.CallSite | ||
|
|
||
| /** | ||
| * Selenium tests for the Spark Web UI with real web browsers. | ||
| */ | ||
| abstract class RealBrowserUISeleniumSuite(val driverProp: String) | ||
| extends SparkFunSuite with WebBrowser with Matchers with BeforeAndAfterAll { | ||
|
|
||
| implicit var webDriver: WebDriver | ||
| private val driverPropPrefix = "spark.test." | ||
|
|
||
| override def beforeAll(): Unit = { | ||
| super.beforeAll() | ||
| assume( | ||
| sys.props(driverPropPrefix + driverProp) !== null, | ||
| "System property " + driverPropPrefix + driverProp + | ||
| " should be set to the corresponding driver path.") | ||
| sys.props(driverProp) = sys.props(driverPropPrefix + driverProp) | ||
| } | ||
|
|
||
| override def afterAll(): Unit = { | ||
| sys.props.remove(driverProp) | ||
| super.afterAll() | ||
| } | ||
|
|
||
| test("SPARK-31534: text for tooltip should be escaped") { | ||
| withSpark(newSparkContext()) { sc => | ||
| sc.setLocalProperty(CallSite.LONG_FORM, "collect at <console>:25") | ||
| sc.setLocalProperty(CallSite.SHORT_FORM, "collect at <console>:25") | ||
| sc.parallelize(1 to 10).collect | ||
|
|
||
| eventually(timeout(10.seconds), interval(50.milliseconds)) { | ||
| goToUi(sc, "/jobs") | ||
|
|
||
| val jobDesc = | ||
| webDriver.findElement(By.cssSelector("div[class='application-timeline-content']")) | ||
| jobDesc.getAttribute("data-title") should include ("collect at <console>:25") | ||
|
|
||
| goToUi(sc, "/jobs/job/?id=0") | ||
| webDriver.get(sc.ui.get.webUrl.stripSuffix("/") + "/jobs/job/?id=0") | ||
| val stageDesc = webDriver.findElement(By.cssSelector("div[class='job-timeline-content']")) | ||
| stageDesc.getAttribute("data-title") should include ("collect at <console>:25") | ||
|
|
||
| // Open DAG Viz. | ||
| webDriver.findElement(By.id("job-dag-viz")).click() | ||
| val nodeDesc = webDriver.findElement(By.cssSelector("g[class='node_0 node']")) | ||
| nodeDesc.getAttribute("name") should include ("collect at <console>:25") | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Create a test SparkContext with the SparkUI enabled. | ||
| * It is safe to `get` the SparkUI directly from the SparkContext returned here. | ||
| */ | ||
| private def newSparkContext( | ||
| killEnabled: Boolean = true, | ||
| master: String = "local", | ||
| additionalConfs: Map[String, String] = Map.empty): SparkContext = { | ||
| val conf = new SparkConf() | ||
| .setMaster(master) | ||
| .setAppName("test") | ||
| .set(UI_ENABLED, true) | ||
| .set(UI_PORT, 0) | ||
| .set(UI_KILL_ENABLED, killEnabled) | ||
| .set(MEMORY_OFFHEAP_SIZE.key, "64m") | ||
| additionalConfs.foreach { case (k, v) => conf.set(k, v) } | ||
| val sc = new SparkContext(conf) | ||
| assert(sc.ui.isDefined) | ||
| sc | ||
| } | ||
|
|
||
| def goToUi(sc: SparkContext, path: String): Unit = { | ||
| goToUi(sc.ui.get, path) | ||
| } | ||
|
|
||
| def goToUi(ui: SparkUI, path: String): Unit = { | ||
| go to (ui.webUrl.stripSuffix("/") + path) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not using assert?
Do we expect this test suite will be skipped if this condition is not true?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I intentionally use
assumerather thanassertbecause I'd like to check the pre-condition for this suite.I also intends this suite is skipped If the condition is not true.
This suite is effective only when users enable suites which are tagged with
ChromeUITestandspark.test.webdriver.chrome.driveris set.