Skip to content

Commit 498c94e

Browse files
committed
Added failing test
1 parent 587dbfc commit 498c94e

File tree

1 file changed

+44
-13
lines changed

1 file changed

+44
-13
lines changed

backend/molgenis-emx2-webapi/src/test/java/org.molgenis.emx2.web/WebApiSmokeTests.java

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,14 +1241,8 @@ public void testExecuteSubtaskInScriptTask()
12411241
Table jobs = db.getSchema(SYSTEM_SCHEMA).getTable("Scripts");
12421242
jobs.delete(row("name", parentJobName));
12431243
db.dropSchemaIfExists("ScriptWithFileUpload");
1244-
jobs.insert(
1245-
row(
1246-
"name",
1247-
parentJobName,
1248-
"type",
1249-
"python",
1250-
"script",
1251-
"""
1244+
String script =
1245+
"""
12521246
import asyncio
12531247
import logging
12541248
import os
@@ -1266,7 +1260,15 @@ async with Client('http://localhost:8081', token=os.environ['MOLGENIS_TOKEN'], j
12661260
if __name__ == '__main__':
12671261
asyncio.run(main())
12681262
1269-
""",
1263+
""";
1264+
jobs.insert(
1265+
row(
1266+
"name",
1267+
parentJobName,
1268+
"type",
1269+
"python",
1270+
"script",
1271+
script,
12701272
"dependencies",
12711273
"--extra-index-url https://test.pypi.org/simple/\n"
12721274
+ "molgenis-emx2-pyclient>=11.22.0"));
@@ -1279,8 +1281,39 @@ async with Client('http://localhost:8081', token=os.environ['MOLGENIS_TOKEN'], j
12791281
.asString();
12801282

12811283
String url = new ObjectMapper().readTree(result).at("/url").textValue();
1284+
assertTrue(testJobSuccess(url));
1285+
1286+
String failingJobName = "failingJobTest";
1287+
jobs.delete(row("name", failingJobName));
1288+
db.dropSchemaIfExists("ScriptWithFileUpload");
1289+
String scriptFail = script.replace("PET_STORE", "PET_STORES");
1290+
jobs.insert(
1291+
row(
1292+
"name",
1293+
failingJobName,
1294+
"type",
1295+
"python",
1296+
"script",
1297+
scriptFail,
1298+
"dependencies",
1299+
"--extra-index-url https://test.pypi.org/simple/\n"
1300+
+ "molgenis-emx2-pyclient>=11.22.0"));
12821301

1283-
result = given().sessionId(SESSION_ID).get(url).asString();
1302+
result =
1303+
given()
1304+
.sessionId(SESSION_ID)
1305+
.when()
1306+
.post("/api/scripts/" + failingJobName)
1307+
.getBody()
1308+
.asString();
1309+
1310+
url = new ObjectMapper().readTree(result).at("/url").textValue();
1311+
assertFalse(testJobSuccess(url));
1312+
}
1313+
1314+
private static boolean testJobSuccess(String url)
1315+
throws InterruptedException, JsonProcessingException {
1316+
String result = given().sessionId(SESSION_ID).get(url).asString();
12841317

12851318
String status = "WAITING";
12861319
int count = 0;
@@ -1292,9 +1325,7 @@ async with Client('http://localhost:8081', token=os.environ['MOLGENIS_TOKEN'], j
12921325
result = given().sessionId(SESSION_ID).get(url).asString();
12931326
status = new ObjectMapper().readTree(result).at("/status").textValue();
12941327
}
1295-
if (result.contains("ERROR")) {
1296-
fail(result);
1297-
}
1328+
return !status.equals("ERROR");
12981329
}
12991330

13001331
private static String getToken(String email, String password) throws JsonProcessingException {

0 commit comments

Comments
 (0)