Skip to content

Commit

Permalink
Fix the confusing server errors during UI tests (jupyter#1871)
Browse files Browse the repository at this point in the history
* Fix the server errors when renaming directory or removing config file

* Clean unexpected error in assignment_list test

* Should remove file exists error in create assignment and validate assignments

* Try to fix windows test

* Remove kernel errors in create assignment ui test, and use galata helpers

* Remove kernel errors in validate assignment ui test, and use galata helpers

* Fix save notebook when testing  notebook application

* Set the env variable in package.json instead of task.py, to simplify local tests

* Fix notebook tests

* Increase the doc test timeout

* (1)move config creation in beforeEach, (2)fix closing notebook in jupyterlab tests and (3) remove useless notebook saving

* Should remove some more traceback by (1) waiting for a notebook to be ready and (2) killing the kernels on teardown
  • Loading branch information
brichet authored and AlirezaT99 committed Aug 6, 2024
1 parent 43e617d commit 2ae1e49
Show file tree
Hide file tree
Showing 14 changed files with 203 additions and 219 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test-docs-python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
run: |
if [ "${{ matrix.group }}" == "docs" ]; then
echo "GROUP=docs" >> $GITHUB_ENV
echo "TIMEOUT_MINUTES=15" >> $GITHUB_ENV
echo "TIMEOUT_MINUTES=20" >> $GITHUB_ENV
fi
if [ "${{ matrix.group }}" == "python" ]; then
echo "GROUP=python" >> $GITHUB_ENV
Expand Down
56 changes: 35 additions & 21 deletions nbgrader/tests/ui-tests/assignment_list.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ test.beforeEach(async ({ request, tmpPath }) => {

await contents.createDirectory(tmpPath);

if (await contents.fileExists("nbgrader_config.py")){
await contents.deleteFile("nbgrader_config.py");
}
await contents.uploadFile(
path.resolve(__dirname, "./files/nbgrader_config.py"),
"nbgrader_config.py"
);

if (!isWindows) {
exchange_dir = fs.mkdtempSync(
path.join(os.tmpdir(), "nbgrader_exchange_test_")
Expand All @@ -77,29 +85,26 @@ test.beforeEach(async ({ request, tmpPath }) => {
/*
* delete temp directories at the end of test
*/
test.afterEach(async ({ request, tmpPath }) => {
test.afterEach(async ({ request, page, tmpPath }) => {
if (!isWindows) {
fs.rmSync(exchange_dir, { recursive: true, force: true });
fs.rmSync(cache_dir, { recursive: true, force: true });
}

if (request === undefined) throw new Error("Request is undefined.");
const contents = galata.newContentsHelper(request);
const contents = galata.newContentsHelper(request, page);
await contents.deleteDirectory(tmpPath);

if (await contents.fileExists("nbgrader_config.py"))
contents.deleteFile("nbgrader_config.py");
contents.uploadFile(
path.resolve(__dirname, "./files/nbgrader_config.py"),
"nbgrader_config.py"
);
});

/*
* Create a nbgrader file system and modify config
*/
const addCourses = async (request: APIRequestContext, tmpPath: string) => {
const contents = galata.newContentsHelper(request);
const addCourses = async (
request: APIRequestContext,
page: IJupyterLabPageFixture,
tmpPath: string
) => {
const contents = galata.newContentsHelper(request, page);

// copy files from the user guide
const source = path.resolve(
Expand Down Expand Up @@ -235,6 +240,15 @@ test("Open assignment list tab from menu", async ({ page, tmpPath }) => {

if (isNotebook) await page.goto(`tree/${tmpPath}`);

// Creating the config file is useful to avoid server error about the exchange
// directory not writable.
// This is not required for the test, only to have cleaner logs.
await createEnv(testDir, tmpPath, exchange_dir, cache_dir, isWindows);
fs.copyFileSync(
path.resolve(testDir, "nbgrader_config.py"),
path.resolve(testDir, tmpPath, "nbgrader_config.py")
);

const nbgrader_menu = page.locator(`${menuPanelId} div.lm-MenuBar-itemLabel:text("Nbgrader")`);
const assignmentList_menu = page.locator(
'#jp-mainmenu-nbgrader li[data-command="nbgrader:open-assignment-list"]'
Expand Down Expand Up @@ -277,7 +291,7 @@ test("Show assignment list", async ({ page, request, tmpPath }) => {
if (isNotebook) await page.goto(`tree/${tmpPath}`);

await createEnv(testDir, tmpPath, exchange_dir, cache_dir, isWindows);
await addCourses(request, tmpPath);
await addCourses(request, page, tmpPath);
await openAssignmentList(page);

// Wait for DOM of each status
Expand Down Expand Up @@ -311,7 +325,7 @@ test("Multiple released assignments", async ({ page, request, tmpPath }) => {
if (isNotebook) await page.goto(`tree/${tmpPath}`);

await createEnv(testDir, tmpPath, exchange_dir, cache_dir, isWindows);
await addCourses(request, tmpPath);
await addCourses(request, page, tmpPath);
await openAssignmentList(page);

// release two assignments
Expand Down Expand Up @@ -347,7 +361,7 @@ test("Fetch assignments", async ({ page, request, tmpPath }) => {
if (isNotebook) await page.goto(`tree/${tmpPath}`);

await createEnv(testDir, tmpPath, exchange_dir, cache_dir, isWindows);
await addCourses(request, tmpPath);
await addCourses(request, page, tmpPath);
await openAssignmentList(page);

// release some assignments
Expand Down Expand Up @@ -400,7 +414,7 @@ test("Submit assignments", async ({ page, request, tmpPath }) => {

// create directories and config files, and open assignment_list tab
await createEnv(testDir, tmpPath, exchange_dir, cache_dir, isWindows);
await addCourses(request, tmpPath);
await addCourses(request, page, tmpPath);
await openAssignmentList(page);

// release some assignments
Expand Down Expand Up @@ -468,7 +482,7 @@ test("submit assignment missing notebook", async ({

// create directories and config files, and open assignment_list tab
await createEnv(testDir, tmpPath, exchange_dir, cache_dir, isWindows);
await addCourses(request, tmpPath);
await addCourses(request, page, tmpPath);
await openAssignmentList(page);

// release some assignments
Expand Down Expand Up @@ -556,7 +570,7 @@ test("Fetch a second assignment", async ({ page, request, tmpPath }) => {
if (isNotebook) await page.goto(`tree/${tmpPath}`);

await createEnv(testDir, tmpPath, exchange_dir, cache_dir, isWindows);
await addCourses(request, tmpPath);
await addCourses(request, page, tmpPath);
await openAssignmentList(page);

// release some assignments
Expand Down Expand Up @@ -627,7 +641,7 @@ test("Submit another assignments", async ({ page, request, tmpPath }) => {

// create directories and config files, and open assignment_list tab
await createEnv(testDir, tmpPath, exchange_dir, cache_dir, isWindows);
await addCourses(request, tmpPath);
await addCourses(request, page, tmpPath);
await openAssignmentList(page);

// release some assignments
Expand Down Expand Up @@ -681,7 +695,7 @@ test("Validate OK", async ({ page, request, tmpPath }) => {

// create directories and config files, and open assignment_list tab
await createEnv(testDir, tmpPath, exchange_dir, cache_dir, isWindows);
await addCourses(request, tmpPath);
await addCourses(request, page, tmpPath);
await openAssignmentList(page);

// release some assignments
Expand Down Expand Up @@ -731,7 +745,7 @@ test("Validate failure", async ({ page, request, tmpPath }) => {

// create directories and config files, and open assignment_list tab
await createEnv(testDir, tmpPath, exchange_dir, cache_dir, isWindows);
await addCourses(request, tmpPath);
await addCourses(request, page, tmpPath);
await openAssignmentList(page);

// release some assignments
Expand Down Expand Up @@ -785,7 +799,7 @@ test("Missing exchange directory", async ({ page, request, tmpPath }) => {

// create directories and config files
await createEnv(testDir, tmpPath, exchange_dir, cache_dir, isWindows);
await addCourses(request, tmpPath);
await addCourses(request, page, tmpPath);

// delete exchange directory
fs.rmSync(exchange_dir, { recursive: true, force: true });
Expand Down
19 changes: 10 additions & 9 deletions nbgrader/tests/ui-tests/course_list.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ test.beforeEach(async ({ request, tmpPath }) => {

await contents.createDirectory(tmpPath);

if (await contents.fileExists("nbgrader_config.py")){
await contents.deleteFile("nbgrader_config.py");
}
await contents.uploadFile(
path.resolve(__dirname, "./files/nbgrader_config.py"),
"nbgrader_config.py"
);

if (!isWindows) {
exchange_dir = fs.mkdtempSync(
path.join(os.tmpdir(), "nbgrader_exchange_test_")
Expand All @@ -71,22 +79,15 @@ test.beforeEach(async ({ request, tmpPath }) => {
/*
* delete temp directories at the end of test
*/
test.afterEach(async ({ request, tmpPath }) => {
test.afterEach(async ({ request, page, tmpPath }) => {
if (request === undefined) throw new Error("Request is undefined.");
const contents = galata.newContentsHelper(request);
const contents = galata.newContentsHelper(request, page);
await contents.deleteDirectory(tmpPath);

if (!isWindows) {
fs.rmSync(exchange_dir, { recursive: true, force: true });
fs.rmSync(cache_dir, { recursive: true, force: true });
}

if (await contents.fileExists("nbgrader_config.py"))
contents.deleteFile("nbgrader_config.py");
contents.uploadFile(
path.resolve(__dirname, "./files/nbgrader_config.py"),
"nbgrader_config.py"
);
});

/*
Expand Down
Loading

0 comments on commit 2ae1e49

Please sign in to comment.