Skip to content
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

Selenium front end test (Jupyter 2.0) #45

Open
wants to merge 48 commits into
base: react
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
7c15d9d
add files to react branch
labanyamukhopadhyay Jul 23, 2020
b4b2378
add branch travis
labanyamukhopadhyay Jul 23, 2020
40d17d6
reduce wait times
labanyamukhopadhyay Jul 23, 2020
23cc59e
local test passes
labanyamukhopadhyay Jul 24, 2020
90b6219
add waits
labanyamukhopadhyay Jul 24, 2020
678bd22
change to css selector
labanyamukhopadhyay Jul 24, 2020
b048b32
click on card twice
labanyamukhopadhyay Jul 24, 2020
0894c9f
add jobid partition assert
labanyamukhopadhyay Jul 27, 2020
58f6b08
remove slick card
labanyamukhopadhyay Jul 27, 2020
341ab39
change slrum card to contains
labanyamukhopadhyay Jul 27, 2020
220dffa
comment error
labanyamukhopadhyay Jul 27, 2020
1f4cedb
find card by class
labanyamukhopadhyay Jul 27, 2020
0203ee5
edit travis sleep
labanyamukhopadhyay Jul 28, 2020
ade99fb
edit pytest
labanyamukhopadhyay Jul 28, 2020
16eeeb1
add try except
labanyamukhopadhyay Jul 28, 2020
5ff4485
add import exception
labanyamukhopadhyay Jul 28, 2020
8f4a361
fix import
labanyamukhopadhyay Jul 28, 2020
e54dbae
contains text th
labanyamukhopadhyay Jul 28, 2020
93b98ad
trial same page
labanyamukhopadhyay Jul 28, 2020
e33fd36
using slurm launcher
labanyamukhopadhyay Jul 28, 2020
c740d7a
run travis
labanyamukhopadhyay Jul 28, 2020
096dcdd
run travis 2
labanyamukhopadhyay Jul 28, 2020
4b4a281
run travis test
labanyamukhopadhyay Jul 28, 2020
a61782e
travis trial
labanyamukhopadhyay Jul 29, 2020
eeb5020
travis local pass
labanyamukhopadhyay Jul 29, 2020
96839d4
travis trial 2
labanyamukhopadhyay Jul 29, 2020
35470f4
travis trial 3
labanyamukhopadhyay Jul 29, 2020
ef5fa40
travis trial 4
labanyamukhopadhyay Jul 29, 2020
d922e47
update pytest
labanyamukhopadhyay Jul 30, 2020
c1e242d
update pytest 2
labanyamukhopadhyay Jul 30, 2020
2faba34
update pytest 3
labanyamukhopadhyay Jul 30, 2020
1724446
update pytest 4
labanyamukhopadhyay Jul 30, 2020
227ed68
update pytest 5
labanyamukhopadhyay Jul 30, 2020
0f1500b
update pytest 6
labanyamukhopadhyay Jul 30, 2020
3cbd183
removing waits
labanyamukhopadhyay Jul 31, 2020
d1ccd98
adding waits
labanyamukhopadhyay Jul 31, 2020
7e28fda
edit pytest
labanyamukhopadhyay Jul 31, 2020
892122b
edit pytest 2
labanyamukhopadhyay Jul 31, 2020
01272ab
edit pytest 3
labanyamukhopadhyay Jul 31, 2020
58853d4
edit pytest 4
labanyamukhopadhyay Jul 31, 2020
556ab56
edit pytest 5
labanyamukhopadhyay Jul 31, 2020
0778a24
edit pytest 6
labanyamukhopadhyay Jul 31, 2020
9d79846
edit pytest 7
labanyamukhopadhyay Jul 31, 2020
df62cf1
edit pytest 8
labanyamukhopadhyay Jul 31, 2020
d05d0df
edit pytest 9
labanyamukhopadhyay Jul 31, 2020
330b110
add api tests
labanyamukhopadhyay Aug 7, 2020
90be50d
add slurm api tests
labanyamukhopadhyay Aug 13, 2020
3cf8172
update api tests
labanyamukhopadhyay Aug 15, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@

language: python
dist: bionic
# python:
# - '3.6'
# - '3.7'
# nodejs:
# - 10.0.0
# os: osx
# command to run tests
cache: pip
env:
global:
- MOZ_HEADLESS=1
addons:
firefox: "78.0.1"
sudo: required
services:
- xvfb
branches:
only:
- master
- react
before_install:
- sudo apt-get install xvfb
- wget https://github.com/mozilla/geckodriver/releases/download/v0.26.0/geckodriver-v0.26.0-linux64.tar.gz
# - mkdir geckodriver
# - tar -xzf geckodriver-v0.26.0-macos.tar.gz -C geckodriver
# - export PATH=$PATH:$PWD/geckodriver
- sudo tar -xzf geckodriver-v0.26.0-linux64.tar.gz -C /usr/bin
- sudo chmod a+x /usr/bin/geckodriver
# - export DISPLAY=:99.0
# - sh -e /etc/init.d/xvfb start
# - sleep 5 # give xvfb some time to start
install:
- "pip install -r requirements.txt"
- npm install selenium-webdriver@^3.0.0
- curl -o- -L https://yarnpkg.com/install.sh | bash
- node --version
- jupyter --version
- jlpm install
- jlpm run build
- jupyter labextension install


script:
- JUPYTER_TOKEN=secret jupyter-notebook &
- jupyter labextension list
- jupyter lab --port=8845 --NotebookApp.token='' &
- export PATH=$(pwd)/tests:$PATH
- sleep 30
- pytest

# JUPYTER_TOKEN=secret jupyter lab --port=8845 --NotebookApp.token='' &
6 changes: 6 additions & 0 deletions infinite.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh
#SBATCH -C haswell
while [ ! -f /global/ul/n/labanyam/stop]
do
sleep 3000
done
4 changes: 4 additions & 0 deletions jupyterlab_slurm/slurm.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

class ShellExecutionHandler(IPythonHandler):
async def run_command(self, command, stdin=None, cwd=None):
print(command)
commands = shlex.split(command)
process = await asyncio.create_subprocess_exec(*commands,
stdout=asyncio.subprocess.PIPE,
Expand Down Expand Up @@ -101,9 +102,12 @@ async def post(self):
# Have two options to specify SLURM script in the request body: either with a path to the script, or with the script's text contents
if inputType:
if inputType == 'path':
print(self.request.body)
print(self.request.headers['Content-Type'] == 'application/json')
if self.request.headers['Content-Type'] == 'application/json':
script_path = json.loads(self.request.body)["input"]
else:
print("shouldn't be here")
script_path = self.get_body_argument('input')
try:
stdout, stderr, returncode = await self.run_command(sbatch_command + script_path, cwd=outputDir)
Expand Down
4 changes: 4 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
jupyter
jupyterlab>2.0.0
selenium
pytest
1 change: 1 addition & 0 deletions sq_output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
JOBID PARTITION NAME USER ST TIME NODES NODELIST(REASON)
3 changes: 3 additions & 0 deletions squeue
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
cat $DIR/sq_output.txt
2 changes: 2 additions & 0 deletions tests/sbatch
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
echo "Success: Submitted batch job 33241147"
2 changes: 2 additions & 0 deletions tests/scancel
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
echo "Success: scancel 33241147"
2 changes: 2 additions & 0 deletions tests/scontrol
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
echo "Success: scontrol hold 33241147"
3 changes: 3 additions & 0 deletions tests/squeue
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh
echo " 33241147 debug_hsw infinite labanyam R 2:25 1 nid01172"

53 changes: 53 additions & 0 deletions tests/test-api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#http://localhost:8845/
import requests
import pytest
import asyncio
import json
import os
from http.client import HTTPConnection
from urllib.parse import quote
from tornado.websocket import websocket_connect


PORT = os.getenv('TEST_PORT', 8845)
TOKEN = os.getenv('JUPYTER_TOKEN', 'secret')


def test_sbatch():
r = requests.post('http://localhost:8845/sbatch?inputType=contents&outputDir=%2Ftmp&token='+TOKEN, data = '{"input":"#!/bin/sh"}', headers={"content-type": "application/json"} )
assert r.status_code == 200

fail_r = requests.post('http://localhost:8845/sbatch?inputType=contents&outputDir=%2Ftmp&token='+TOKEN, headers={"content-type": "application/json"} )
assert fail_r.status_code != 200

def test_squeue():
jobID = []
r = requests.get('http://localhost:8845/squeue?userOnly=true&token='+ TOKEN)
assert r.status_code == 200
assert len(r.json()['data'][0]) == 8

fail_r = requests.get('http://localhost:8845/squeue&token='+ TOKEN)
print(fail_r.text)
assert fail_r.status_code != 200


def test_scontrol():
r = requests.patch('http://localhost:8845/scontrol/hold?token='+ TOKEN, data = json.dumps({ "jobID": '33241147' }), headers={"content-type": "application/json"})
assert r.status_code == 200
assert ("Success: scontrol hold") in r.json()['responseMessage']

fail_r = requests.patch('http://localhost:8845/scontrol/hold?token='+ TOKEN, headers={"content-type": "application/json"})
assert fail_r.status_code != 200


def test_scancel():
r = requests.delete('http://localhost:8845/scancel?token=' + TOKEN, data = json.dumps({ "jobID": '33241147' }), headers={"content-type": "application/json"})
assert r.status_code == 200
assert ("Success: scancel") in r.json()['responseMessage']

fail_r = requests.delete('http://localhost:8845/scancel?token=' + TOKEN, data = json.dumps({ "jobID": '33241147' }))
assert fail_r.status_code != 200

if __name__ == '__main__':
test_sbatch()
test_squeue()
114 changes: 114 additions & 0 deletions tests/test_slurm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
import pytest
import time
import json
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.common.exceptions import NoSuchElementException

class TestAddfavs():
def setup_method(self, method):
self.driver = webdriver.Firefox()
self.vars = {}

def teardown_method(self, method):
self.driver.quit()

# def test_slurmcard(self):
# #import pdb; pdb.set_trace()

# self.driver.get("http://localhost:8845/lab")
# self.driver.implicitly_wait(40)
# self.driver.maximize_window()
# self.driver.implicitly_wait(40)

# #card_text = self.driver.find_element(By.XPATH, "/html/body/div/div[3]/div[2]/div[3]/div[3]/div[2]/div/div/div[5]/div[2]/div")
# #assert card_text.text == "Slurm Queue"

# slurm_card = self.driver.find_elements_by_class_name('jp-NerscLaunchIcon')
# #slurm_card = self.driver.find_element_by_css_selector(".jp-NerscLaunchIcon.jp-Launcher-icon")
# #assert slurm_card.text == "Slurm Queue"
# self.driver.implicitly_wait(40)
# #self.driver.execute_script("return arguments[0].scrollIntoView(0, document.documentElement.scrollHeight-10);", slurm_card)
# #self.driver.implicitly_wait(20)
# #actions.click(slurm_card[1]).perform()
# actions = ActionChains(self.driver)
# actions.click(slurm_card[1]).perform()
# #actions.click(slurm_card).perform()
# #actions = ActionChains(self.driver)
# #actions.move_to_element(slurm_launcher).perform()
# #actions = ActionChains(self.driver)
# #actions.click(slurm_launcher).perform()
# self.driver.implicitly_wait(40)

# # try:
# # jobid_text = self.driver.find_element(By.XPATH, "//*[contains(text(),'JOBID')]")
# # assert jobid_text.text == "JOBID"

# # partition_text = self.driver.find_element(By.XPATH, "//*[contains(text(),'PARTITION')]")
# # assert partition_text.text == "PARTITION"

# # close_tab = self.driver.find_element(By.XPATH, "/html/body/div/div[3]/div[2]/div[3]/div[2]/ul/li[2]/div[3]")
# # actions = ActionChains(self.driver)
# # actions.click(close_tab).perform()
# # except NoSuchElementException:
# # print('No slurm elements found')

# # jobid_text = self.driver.find_element(By.XPATH, "//h2[contains(text(),'HPC Tools')]")
# # assert jobid_text.text == "HPC Tools"

# jobid_text = self.driver.find_element(By.XPATH, "//th[contains(text(),'JOBID')]")
# assert jobid_text.text == "JOBID"

# partition_text = self.driver.find_element(By.XPATH, "//th[contains(text(),'PARTITION')]")
# assert partition_text.text == "PARTITION"

# #close_tab = self.driver.find_element(By.XPATH, "/html/body/div/div[3]/div[2]/div[3]/div[2]/ul/li[2]/div[3]")
# #close_tab = self.driver.find_element(By.XPATH, "/html/body/div/div[3]/div[2]/div[3]/div[2]/ul/li/div[3]")
# close_tab = self.driver.find_element(By.XPATH, "/html/body/div/div[3]/div[2]/div[3]/div[2]/ul/li/div[3]")

# actions = ActionChains(self.driver)
# actions.click(close_tab).perform()

def test_slurmcommands(self):
#import pdb; pdb.set_trace()

self.driver.get("http://localhost:8845/lab")
self.driver.implicitly_wait(40)
self.driver.maximize_window()
self.driver.implicitly_wait(40)

console = self.driver.find_element(By.XPATH, '//*[@data-id="command-palette"]')
self.driver.implicitly_wait(30)
actions = ActionChains(self.driver)
actions.click(console).perform()
self.driver.implicitly_wait(40)

slurm_launcher = self.driver.find_element(By.XPATH, "//div[contains(text(),'Slurm Queue')]")
self.driver.implicitly_wait(20)
self.driver.execute_script("return arguments[0].scrollIntoView(0, document.documentElement.scrollHeight-10);", slurm_launcher)
#actions.move_to_element(slurm_launcher).perform()
self.driver.implicitly_wait(60)
actions = ActionChains(self.driver)
actions.click(slurm_launcher).perform()

self.driver.implicitly_wait(40)
jobid_text = self.driver.find_element(By.XPATH, "//th[contains(text(),'JOBID')]")
assert jobid_text.text == "JOBID"

partition_text = self.driver.find_element(By.XPATH, "//th[contains(text(),'PARTITION')]")
assert partition_text.text == "PARTITION"

self.driver.implicitly_wait(40)



if __name__ == '__main__':
setup_method()
#test_slurmcard()
test_slurmcommands()
teardown_method()