Skip to content

Commit 6bfd5a4

Browse files
authored
Fix the confusing server errors during UI tests (#1871)
* 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
1 parent 08fcced commit 6bfd5a4

14 files changed

+203
-219
lines changed

.github/workflows/test-docs-python.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ jobs:
4848
run: |
4949
if [ "${{ matrix.group }}" == "docs" ]; then
5050
echo "GROUP=docs" >> $GITHUB_ENV
51-
echo "TIMEOUT_MINUTES=15" >> $GITHUB_ENV
51+
echo "TIMEOUT_MINUTES=20" >> $GITHUB_ENV
5252
fi
5353
if [ "${{ matrix.group }}" == "python" ]; then
5454
echo "GROUP=python" >> $GITHUB_ENV

nbgrader/tests/ui-tests/assignment_list.spec.ts

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,14 @@ test.beforeEach(async ({ request, tmpPath }) => {
6666

6767
await contents.createDirectory(tmpPath);
6868

69+
if (await contents.fileExists("nbgrader_config.py")){
70+
await contents.deleteFile("nbgrader_config.py");
71+
}
72+
await contents.uploadFile(
73+
path.resolve(__dirname, "./files/nbgrader_config.py"),
74+
"nbgrader_config.py"
75+
);
76+
6977
if (!isWindows) {
7078
exchange_dir = fs.mkdtempSync(
7179
path.join(os.tmpdir(), "nbgrader_exchange_test_")
@@ -77,29 +85,26 @@ test.beforeEach(async ({ request, tmpPath }) => {
7785
/*
7886
* delete temp directories at the end of test
7987
*/
80-
test.afterEach(async ({ request, tmpPath }) => {
88+
test.afterEach(async ({ request, page, tmpPath }) => {
8189
if (!isWindows) {
8290
fs.rmSync(exchange_dir, { recursive: true, force: true });
8391
fs.rmSync(cache_dir, { recursive: true, force: true });
8492
}
8593

8694
if (request === undefined) throw new Error("Request is undefined.");
87-
const contents = galata.newContentsHelper(request);
95+
const contents = galata.newContentsHelper(request, page);
8896
await contents.deleteDirectory(tmpPath);
89-
90-
if (await contents.fileExists("nbgrader_config.py"))
91-
contents.deleteFile("nbgrader_config.py");
92-
contents.uploadFile(
93-
path.resolve(__dirname, "./files/nbgrader_config.py"),
94-
"nbgrader_config.py"
95-
);
9697
});
9798

9899
/*
99100
* Create a nbgrader file system and modify config
100101
*/
101-
const addCourses = async (request: APIRequestContext, tmpPath: string) => {
102-
const contents = galata.newContentsHelper(request);
102+
const addCourses = async (
103+
request: APIRequestContext,
104+
page: IJupyterLabPageFixture,
105+
tmpPath: string
106+
) => {
107+
const contents = galata.newContentsHelper(request, page);
103108

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

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

243+
// Creating the config file is useful to avoid server error about the exchange
244+
// directory not writable.
245+
// This is not required for the test, only to have cleaner logs.
246+
await createEnv(testDir, tmpPath, exchange_dir, cache_dir, isWindows);
247+
fs.copyFileSync(
248+
path.resolve(testDir, "nbgrader_config.py"),
249+
path.resolve(testDir, tmpPath, "nbgrader_config.py")
250+
);
251+
238252
const nbgrader_menu = page.locator(`${menuPanelId} div.lm-MenuBar-itemLabel:text("Nbgrader")`);
239253
const assignmentList_menu = page.locator(
240254
'#jp-mainmenu-nbgrader li[data-command="nbgrader:open-assignment-list"]'
@@ -277,7 +291,7 @@ test("Show assignment list", async ({ page, request, tmpPath }) => {
277291
if (isNotebook) await page.goto(`tree/${tmpPath}`);
278292

279293
await createEnv(testDir, tmpPath, exchange_dir, cache_dir, isWindows);
280-
await addCourses(request, tmpPath);
294+
await addCourses(request, page, tmpPath);
281295
await openAssignmentList(page);
282296

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

313327
await createEnv(testDir, tmpPath, exchange_dir, cache_dir, isWindows);
314-
await addCourses(request, tmpPath);
328+
await addCourses(request, page, tmpPath);
315329
await openAssignmentList(page);
316330

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

349363
await createEnv(testDir, tmpPath, exchange_dir, cache_dir, isWindows);
350-
await addCourses(request, tmpPath);
364+
await addCourses(request, page, tmpPath);
351365
await openAssignmentList(page);
352366

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

401415
// create directories and config files, and open assignment_list tab
402416
await createEnv(testDir, tmpPath, exchange_dir, cache_dir, isWindows);
403-
await addCourses(request, tmpPath);
417+
await addCourses(request, page, tmpPath);
404418
await openAssignmentList(page);
405419

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

469483
// create directories and config files, and open assignment_list tab
470484
await createEnv(testDir, tmpPath, exchange_dir, cache_dir, isWindows);
471-
await addCourses(request, tmpPath);
485+
await addCourses(request, page, tmpPath);
472486
await openAssignmentList(page);
473487

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

558572
await createEnv(testDir, tmpPath, exchange_dir, cache_dir, isWindows);
559-
await addCourses(request, tmpPath);
573+
await addCourses(request, page, tmpPath);
560574
await openAssignmentList(page);
561575

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

628642
// create directories and config files, and open assignment_list tab
629643
await createEnv(testDir, tmpPath, exchange_dir, cache_dir, isWindows);
630-
await addCourses(request, tmpPath);
644+
await addCourses(request, page, tmpPath);
631645
await openAssignmentList(page);
632646

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

682696
// create directories and config files, and open assignment_list tab
683697
await createEnv(testDir, tmpPath, exchange_dir, cache_dir, isWindows);
684-
await addCourses(request, tmpPath);
698+
await addCourses(request, page, tmpPath);
685699
await openAssignmentList(page);
686700

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

732746
// create directories and config files, and open assignment_list tab
733747
await createEnv(testDir, tmpPath, exchange_dir, cache_dir, isWindows);
734-
await addCourses(request, tmpPath);
748+
await addCourses(request, page, tmpPath);
735749
await openAssignmentList(page);
736750

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

786800
// create directories and config files
787801
await createEnv(testDir, tmpPath, exchange_dir, cache_dir, isWindows);
788-
await addCourses(request, tmpPath);
802+
await addCourses(request, page, tmpPath);
789803

790804
// delete exchange directory
791805
fs.rmSync(exchange_dir, { recursive: true, force: true });

nbgrader/tests/ui-tests/course_list.spec.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,14 @@ test.beforeEach(async ({ request, tmpPath }) => {
6060

6161
await contents.createDirectory(tmpPath);
6262

63+
if (await contents.fileExists("nbgrader_config.py")){
64+
await contents.deleteFile("nbgrader_config.py");
65+
}
66+
await contents.uploadFile(
67+
path.resolve(__dirname, "./files/nbgrader_config.py"),
68+
"nbgrader_config.py"
69+
);
70+
6371
if (!isWindows) {
6472
exchange_dir = fs.mkdtempSync(
6573
path.join(os.tmpdir(), "nbgrader_exchange_test_")
@@ -71,22 +79,15 @@ test.beforeEach(async ({ request, tmpPath }) => {
7179
/*
7280
* delete temp directories at the end of test
7381
*/
74-
test.afterEach(async ({ request, tmpPath }) => {
82+
test.afterEach(async ({ request, page, tmpPath }) => {
7583
if (request === undefined) throw new Error("Request is undefined.");
76-
const contents = galata.newContentsHelper(request);
84+
const contents = galata.newContentsHelper(request, page);
7785
await contents.deleteDirectory(tmpPath);
7886

7987
if (!isWindows) {
8088
fs.rmSync(exchange_dir, { recursive: true, force: true });
8189
fs.rmSync(cache_dir, { recursive: true, force: true });
8290
}
83-
84-
if (await contents.fileExists("nbgrader_config.py"))
85-
contents.deleteFile("nbgrader_config.py");
86-
contents.uploadFile(
87-
path.resolve(__dirname, "./files/nbgrader_config.py"),
88-
"nbgrader_config.py"
89-
);
9091
});
9192

9293
/*

0 commit comments

Comments
 (0)